[GH-ISSUE #21737] issue: Tag duplicate-key errors: unique index on tag(id) conflicts with PK(id, user_id) #19556

Closed
opened 2026-04-20 02:02:27 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @martional on GitHub (Feb 22, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/21737

Check Existing Issues

  • I have searched for any existing and/or related issues.
  • I have searched for any existing and/or related discussions.
  • I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!).
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

v0.8.3

Ollama Version (if applicable)

N/A

Operating System

Ubuntu 22.04

Browser (if applicable)

Chrome 120

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have provided every relevant configuration, setting, and environment variable used in my setup.
  • I have clearly listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc).
  • I have documented step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation. My steps:
  • Start with the initial platform/version/OS and dependencies used,
  • Specify exact install/launch/configure commands,
  • List URLs visited, user input (incl. example values/emails/passwords if needed),
  • Describe all options and toggles enabled or changed,
  • Include any files or environmental changes,
  • Identify the expected and actual result at each stage,
  • Ensure any reasonably skilled user can follow and hit the same issue.

Expected Behavior

Expected Behavior

Tags should be uniquely identified by the composite key (id, user_id). Multiple users can have tags with the same id (e.g. both User A and User B can have a tag named "work"). No unique constraint should exist on id alone. Tag creation and updates should succeed without duplicate-key errors.

Actual Behavior

Actual Behavior

Duplicate-key errors occur when inserting or updating tags. The database rejects the operation because a unique index on tag.id alone conflicts with the intended composite primary key (id, user_id).

Typical errors:

  • SQLite: UNIQUE constraint failed: tag.id
  • PostgreSQL: duplicate key value violates unique constraint

This happens when two different users create a tag with the same name, or when tag operations trigger inserts that conflict with the leftover unique index on id.

Steps to Reproduce

Steps to Reproduce

  1. Set up Open WebUI v0.8.3 on Ubuntu 22.04 using Docker (e.g. docker run -d -p 8080:8080 --name open-webui ghcr.io/open-webui/open-webui:main).
  2. Ensure the database is SQLite (default) or PostgreSQL.
  3. Create the first user (e.g. User A) and log in.
  4. Create a tag (e.g. "work") by adding it to a chat or via the tag UI.
  5. Create a second user (User B) and log in.
  6. As User B, create the same tag name (e.g. "work") by adding it to a chat.
  7. Observe the duplicate-key / unique constraint error (in the UI or in Docker logs).

Alternative:

  • If the issue persists from an older upgrade, the error may occur during normal tag operations (e.g. adding a tag to a chat) when the database still has a unique index on tag.id from the original schema.

Prerequisites: Database must have been created or migrated from a version where the tag table had PK(id) and the migration to PK(id, user_id) did not fully remove the unique index on id alone.

Logs & Screenshots

Logs & Screenshots

Docker logs:

docker logs <container_name> 2>&1 | tail -100

Example error (SQLite):

sqlite3.OperationalError: UNIQUE constraint failed: tag.id

Example error (PostgreSQL):

sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint ...

Database check (optional):

-- SQLite: list indexes on tag table
SELECT name, sql FROM sqlite_master WHERE type='index' AND tbl_name='tag';

If you see a unique index on id alone (e.g. sqlite_autoindex_tag_1 or similar), that confirms the issue.

Additional Information

Additional Information

Root cause: The tag table was originally created with PrimaryKeyConstraint("id") in the init migration. Migration 1af9b942657b added user_id and created uq_id_user_id on (id, user_id). Migration 3ab32c4b8f59 changed the PK to (id, user_id) and attempted to drop conflicting constraints. In some upgrade paths or database engines (e.g. SQLite autoindexes, or different upgrade orders), a unique index on id alone can persist and cause the errors described above.

Proposed fix: A follow-up migration that explicitly drops any unique index on tag.id alone (if it exists) would resolve the issue for affected installations.

Originally created by @martional on GitHub (Feb 22, 2026). Original GitHub issue: https://github.com/open-webui/open-webui/issues/21737 ### Check Existing Issues - [x] I have searched for any existing and/or related issues. - [x] I have searched for any existing and/or related discussions. - [x] I have also searched in the CLOSED issues AND CLOSED discussions and found no related items (your issue might already be addressed on the development branch!). - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version v0.8.3 ### Ollama Version (if applicable) N/A ### Operating System Ubuntu 22.04 ### Browser (if applicable) Chrome 120 ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have **provided every relevant configuration, setting, and environment variable used in my setup.** - [x] I have clearly **listed every relevant configuration, custom setting, environment variable, and command-line option that influences my setup** (such as Docker Compose overrides, .env values, browser settings, authentication configurations, etc). - [x] I have documented **step-by-step reproduction instructions that are precise, sequential, and leave nothing to interpretation**. My steps: - Start with the initial platform/version/OS and dependencies used, - Specify exact install/launch/configure commands, - List URLs visited, user input (incl. example values/emails/passwords if needed), - Describe all options and toggles enabled or changed, - Include any files or environmental changes, - Identify the expected and actual result at each stage, - Ensure any reasonably skilled user can follow and hit the same issue. ### Expected Behavior ## Expected Behavior Tags should be uniquely identified by the composite key `(id, user_id)`. Multiple users can have tags with the same `id` (e.g. both User A and User B can have a tag named "work"). No unique constraint should exist on `id` alone. Tag creation and updates should succeed without duplicate-key errors. ### Actual Behavior ## Actual Behavior Duplicate-key errors occur when inserting or updating tags. The database rejects the operation because a unique index on `tag.id` alone conflicts with the intended composite primary key `(id, user_id)`. **Typical errors:** - SQLite: `UNIQUE constraint failed: tag.id` - PostgreSQL: `duplicate key value violates unique constraint` This happens when two different users create a tag with the same name, or when tag operations trigger inserts that conflict with the leftover unique index on `id`. ### Steps to Reproduce ## Steps to Reproduce 1. Set up Open WebUI v0.8.3 on Ubuntu 22.04 using Docker (e.g. `docker run -d -p 8080:8080 --name open-webui ghcr.io/open-webui/open-webui:main`). 2. Ensure the database is SQLite (default) or PostgreSQL. 3. Create the first user (e.g. User A) and log in. 4. Create a tag (e.g. "work") by adding it to a chat or via the tag UI. 5. Create a second user (User B) and log in. 6. As User B, create the same tag name (e.g. "work") by adding it to a chat. 7. Observe the duplicate-key / unique constraint error (in the UI or in Docker logs). **Alternative:** - If the issue persists from an older upgrade, the error may occur during normal tag operations (e.g. adding a tag to a chat) when the database still has a unique index on `tag.id` from the original schema. **Prerequisites:** Database must have been created or migrated from a version where the tag table had `PK(id)` and the migration to `PK(id, user_id)` did not fully remove the unique index on `id` alone. ### Logs & Screenshots ## Logs & Screenshots **Docker logs:** ``` docker logs <container_name> 2>&1 | tail -100 ``` **Example error (SQLite):** ``` sqlite3.OperationalError: UNIQUE constraint failed: tag.id ``` **Example error (PostgreSQL):** ``` sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint ... ``` **Database check (optional):** ```sql -- SQLite: list indexes on tag table SELECT name, sql FROM sqlite_master WHERE type='index' AND tbl_name='tag'; ``` If you see a unique index on `id` alone (e.g. `sqlite_autoindex_tag_1` or similar), that confirms the issue. ### Additional Information ## Additional Information **Root cause:** The `tag` table was originally created with `PrimaryKeyConstraint("id")` in the init migration. Migration `1af9b942657b` added `user_id` and created `uq_id_user_id` on `(id, user_id)`. Migration `3ab32c4b8f59` changed the PK to `(id, user_id)` and attempted to drop conflicting constraints. In some upgrade paths or database engines (e.g. SQLite autoindexes, or different upgrade orders), a unique index on `id` alone can persist and cause the errors described above. **Proposed fix:** A follow-up migration that explicitly drops any unique index on `tag.id` alone (if it exists) would resolve the issue for affected installations.
GiteaMirror added the bug label 2026-04-20 02:02:27 -05:00
Author
Owner

@tjbck commented on GitHub (Feb 22, 2026):

Unable to reproduce, we never had unique id constraint afaik.

<!-- gh-comment-id:3941646597 --> @tjbck commented on GitHub (Feb 22, 2026): Unable to reproduce, we never had unique id constraint afaik.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#19556