Testing: Migration is idempotent; tested logic matches existing migration patterns
Agentic AI Code: Human-reviewed and manually verified
Code review: Self-reviewed against project migration style
Title Prefix: fix
Description
Drops any leftover unique index on tag.id alone that conflicts with the composite primary key (id, user_id). In some upgrade paths or database engines, a unique index on id alone can persist from the original schema and cause UNIQUE constraint failed: tag.id (SQLite) or equivalent errors when multiple users create tags with the same name.
Changes:
Add migration c8d4e5f6a7b8_drop_tag_id_unique_index.py that inspects the tag table and drops any unique index on id alone if it exists
Migration is idempotent and safe: only drops indexes that match the problematic pattern
No downgrade (intentional: we don't recreate the problematic index)
Changelog Entry
Description
Add migration to drop unique index on tag.id when it conflicts with composite PK (id, user_id), fixing duplicate-key errors when multiple users create tags with the same name.
Fixed
Tag duplicate-key errors: UNIQUE constraint failed: tag.id (SQLite) / duplicate key violation (PostgreSQL) when different users create tags with the same name
Migration 3ab32c4b8f59_update_tags.py attempted to drop conflicting indexes, but in some upgrade paths a unique index on id alone can persist. This migration explicitly drops such indexes if they exist.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/21739
**Author:** [@martional](https://github.com/martional)
**Created:** 2/22/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `fix/drop-tag-id-unique-index`
---
### 📝 Commits (1)
- [`0e4622c`](https://github.com/open-webui/open-webui/commit/0e4622c3ac9003fab496563302c768f6d8d40a49) fix: drop unique index on tag(id) to fix duplicate-key errors
### 📊 Changes
**1 file changed** (+53 additions, -0 deletions)
<details>
<summary>View changed files</summary>
➕ `backend/open_webui/migrations/versions/c8d4e5f6a7b8_drop_tag_id_unique_index.py` (+53 -0)
</details>
### 📄 Description
# fix: drop unique index on tag(id) to fix duplicate-key errors
Fixes #21737
## Pull Request Checklist
- [x] **Target branch:** Targets the `dev` branch
- [x] **Description:** See below
- [x] **Changelog:** Added at bottom
- [ ] **Documentation:** N/A – migration only
- [ ] **Dependencies:** None
- [x] **Testing:** Migration is idempotent; tested logic matches existing migration patterns
- [x] **Agentic AI Code:** Human-reviewed and manually verified
- [x] **Code review:** Self-reviewed against project migration style
- [x] **Title Prefix:** fix
## Description
Drops any leftover unique index on `tag.id` alone that conflicts with the composite primary key `(id, user_id)`. In some upgrade paths or database engines, a unique index on `id` alone can persist from the original schema and cause `UNIQUE constraint failed: tag.id` (SQLite) or equivalent errors when multiple users create tags with the same name.
**Changes:**
- Add migration `c8d4e5f6a7b8_drop_tag_id_unique_index.py` that inspects the tag table and drops any unique index on `id` alone if it exists
- Migration is idempotent and safe: only drops indexes that match the problematic pattern
- No downgrade (intentional: we don't recreate the problematic index)
---
# Changelog Entry
### Description
- Add migration to drop unique index on `tag.id` when it conflicts with composite PK `(id, user_id)`, fixing duplicate-key errors when multiple users create tags with the same name.
### Fixed
- Tag duplicate-key errors: `UNIQUE constraint failed: tag.id` (SQLite) / duplicate key violation (PostgreSQL) when different users create tags with the same name
### Additional Information
- Related issue: #21737
- Migration `3ab32c4b8f59_update_tags.py` attempted to drop conflicting indexes, but in some upgrade paths a unique index on `id` alone can persist. This migration explicitly drops such indexes if they exist.
### Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21739
Author: @martional
Created: 2/22/2026
Status: ❌ Closed
Base:
dev← Head:fix/drop-tag-id-unique-index📝 Commits (1)
0e4622cfix: drop unique index on tag(id) to fix duplicate-key errors📊 Changes
1 file changed (+53 additions, -0 deletions)
View changed files
➕
backend/open_webui/migrations/versions/c8d4e5f6a7b8_drop_tag_id_unique_index.py(+53 -0)📄 Description
fix: drop unique index on tag(id) to fix duplicate-key errors
Fixes #21737
Pull Request Checklist
devbranchDescription
Drops any leftover unique index on
tag.idalone that conflicts with the composite primary key(id, user_id). In some upgrade paths or database engines, a unique index onidalone can persist from the original schema and causeUNIQUE constraint failed: tag.id(SQLite) or equivalent errors when multiple users create tags with the same name.Changes:
c8d4e5f6a7b8_drop_tag_id_unique_index.pythat inspects the tag table and drops any unique index onidalone if it existsChangelog Entry
Description
tag.idwhen it conflicts with composite PK(id, user_id), fixing duplicate-key errors when multiple users create tags with the same name.Fixed
UNIQUE constraint failed: tag.id(SQLite) / duplicate key violation (PostgreSQL) when different users create tags with the same nameAdditional Information
3ab32c4b8f59_update_tags.pyattempted to drop conflicting indexes, but in some upgrade paths a unique index onidalone can persist. This migration explicitly drops such indexes if they exist.Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.