#26034 closed Bug (fixed)
Altering CharFields to have both db_index=True and unique=True crashes on postgresql
Reported by: | Karl Hobley | Owned by: | Tim Graham |
---|---|---|---|
Component: | Migrations | Version: | 1.8 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi Everyone,
If you have a CharField with db_index=True and alter it to have both "db_index=True" and "unique=True" the migration for this will not run on PostgreSQL.
Instead, you will get the following error:
django.db.utils.ProgrammingError: relation "app_mymodel_my_field_3922656f_like" already exists
This bug apears to have been introduced in Django 1.8.7/1.9.1. Git bisect leads to this commit: https://github.com/django/django/commit/722fae4b5159b2810e252e3385936f86f04eb09b
I have created a test project that should hopefully help diagnosis: https://github.com/kaedroho/djangobugtest2/
Thanks,
Karl
Change History (17)
comment:1 by , 9 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 1.9 → 1.8 |
comment:2 by , 9 years ago
Component: | Database layer (models, ORM) → Migrations |
---|
comment:4 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 9 years ago
PR (have to double check a few things tomorrow, so not checking 'has patch' yet)
comment:6 by , 9 years ago
Has patch: | set |
---|
comment:7 by , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Docs say, "Note that when
unique
isTrue
, you don’t need to specifydb_index
, because unique implies the creation of an index." Nonetheless, we should handle this case gracefully.