ORM migration index name mismatch. Can't drop existing index.

30 views
Skip to first unread message

Konstantin Kuchkov

unread,
May 16, 2022, 6:09:06 PM5/16/22
to Django users
Context:
In an app called "exams", I have a model named Capture which has a unique CharField named "uuid". I was trying to convert this field to a UUIDField and I was getting this error:
django.db.utils.ProgrammingError: operator class "varchar_pattern_ops" does not accept data type uuid

Looking at the postgres table I found this index
"exams_capture_uuid_4a3af4ea353edaa5_like" btree (uuid varchar_pattern_ops)
However, the migration was trying to drop an index by a different name
DROP INDEX IF EXISTS "exams_capture_uuid_0c20e2c2_like";
Works correctly if I add a RunSQL migration to remove the culprit.

So I'm wondering where did the other index name come from? We never mess with postgres schema without going through Django ORM.
Originally, the table was created in Django 1.11, and, currently, we're on Django 4.04. Did something change between versions that caused index naming to be different? I checked the initial migration with sqlmigrate and even that shows the new index name.

Is there a way to work around this without hardcoding index name in raw sql?
Reply all
Reply to author
Forward
0 new messages