I'm trying to migrate my Django application which uses jazzband django-taggit The error I get is:
django.db.utils.IntegrityError: could not create unique index "taggit_taggeditem_content_type_id_object_i_4bb97a8e_uniq"
DETAIL: Key (content_type_id, object_id, tag_id)=(41, 596, 242) is duplicated.
The migration in question reads:
migrations.AlterUniqueTogether(
name="taggeditem", unique_together={("content_type", "object_id", "tag")}
)
Which translates to the following SQL:
ALTER TABLE "taggit_taggeditem" ADD CONSTRAINT "taggit_taggeditem_content_type_id_object_i_4bb97a8e_uniq" UNIQUE ("content_type_id", "object_id", "tag_id");
COMMIT;
Checking the table in question I do get:
# SELECT * FROM public.taggit_taggeditem WHERE tag_id=242 ORDER BY object_id;
id | tag_id | object_id | content_type_id
------+--------+-----------+-----------------
691 | 242 | 356 | 41
2904 | 242 | 356 | 41
680 | 242 | 486 | 41
2893 | 242 | 486 | 41
683 | 242 | 596 | 41
2896 | 242 | 596 | 41
What is the suggested way to resolve the django.db.utils.IntegrityError
error and successfully finish the migration? I think the same will happen with object_id 486 and 356 (+ several more).