Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Tim Graham, 8 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Version: 1.91.8

Docs say, "Note that when unique is True, you don’t need to specify db_index, because unique implies the creation of an index." Nonetheless, we should handle this case gracefully.

comment:2 by Simon Charette, 8 years ago

Component: Database layer (models, ORM)Migrations

comment:3 by Simon Charette, 8 years ago

i wonder if this could be related to #25694.

comment:4 by Tim Graham, 8 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:5 by Tim Graham, 8 years ago

PR (have to double check a few things tomorrow, so not checking 'has patch' yet)

comment:6 by Tim Graham, 8 years ago

Has patch: set

comment:7 by Simon Charette, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 56aaae58:

Fixed #26034 -- Fixed incorrect index handling on PostgreSQL on Char/TextField with unique=True and db_index=True.

Thanks Simon Charette for review.

comment:9 by Tim Graham <timograham@…>, 8 years ago

In 3d324b9:

[1.9.x] Fixed #26034 -- Fixed incorrect index handling on PostgreSQL on Char/TextField with unique=True and db_index=True.

Thanks Simon Charette for review.

Backport of 56aaae58a746eb39d5e92ba60f59f4c750a8e1a8 from master

comment:10 by Tim Graham <timograham@…>, 8 years ago

In f8c3d38c:

[1.8.x] Fixed #26034 -- Fixed incorrect index handling on PostgreSQL on Char/TextField with unique=True and db_index=True.

Thanks Simon Charette for review.

Backport of 56aaae58a746eb39d5e92ba60f59f4c750a8e1a8 from master

comment:11 by Tim Graham <timograham@…>, 8 years ago

In 497b5d6:

Refs #26034 -- Added another case fixed by this ticket to release notes.

Thanks Shai Berger for the report.

comment:12 by Tim Graham <timograham@…>, 8 years ago

In 5e8685c:

Refs #26034 -- Added another case fixed by this ticket to release notes.

comment:13 by Tim Graham <timograham@…>, 8 years ago

In 4aec49d:

[1.9.x] Refs #26034 -- Added another case fixed by this ticket to release notes.

Thanks Shai Berger for the report.

Backport of 497b5d6feee5b7947231bd0ae6edf833773b6cce and
5e8685c1b14e94e3f540ac1d68b61e71dcc27517 from master

comment:14 by Tim Graham <timograham@…>, 8 years ago

In 7b6ab28:

[1.8.x] Refs #26034 -- Added another case fixed by this ticket to release notes.

Thanks Shai Berger for the report.

Backport of 497b5d6feee5b7947231bd0ae6edf833773b6cce from master

comment:15 by Tim Graham <timograham@…>, 8 years ago

In d47f6d75:

Refs #26034 -- Corrected a schema test to work with the correct field state.

comment:16 by Tim Graham <timograham@…>, 8 years ago

In 5c048524:

[1.10.x] Refs #26034 -- Corrected a schema test to work with the correct field state.

Backport of d47f6d75ef67dbd18abf2bb927753f739a9c117d from master

comment:17 by Tim Graham <timograham@…>, 8 years ago

In 54c0dea:

[1.9.x] Refs #26034 -- Corrected a schema test to work with the correct field state.

Backport of d47f6d75ef67dbd18abf2bb927753f739a9c117d from master

Note: See TracTickets for help on using tickets.
Back to Top