Opened 4 years ago

Closed 4 years ago

Last modified 3 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 Changed 4 years ago by Tim Graham

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 Changed 4 years ago by Simon Charette

Component: Database layer (models, ORM)Migrations

comment:3 Changed 4 years ago by Simon Charette

i wonder if this could be related to #25694.

comment:4 Changed 4 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:5 Changed 4 years ago by Tim Graham

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

comment:6 Changed 4 years ago by Tim Graham

Has patch: set

comment:7 Changed 4 years ago by Simon Charette

Triage Stage: AcceptedReady for checkin

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

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 Changed 4 years ago by Tim Graham <timograham@…>

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 Changed 4 years ago by Tim Graham <timograham@…>

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 Changed 4 years ago by Tim Graham <timograham@…>

In 497b5d6:

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

Thanks Shai Berger for the report.

comment:12 Changed 4 years ago by Tim Graham <timograham@…>

In 5e8685c:

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

comment:13 Changed 4 years ago by Tim Graham <timograham@…>

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 Changed 4 years ago by Tim Graham <timograham@…>

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 Changed 3 years ago by Tim Graham <timograham@…>

In d47f6d75:

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

comment:16 Changed 3 years ago by Tim Graham <timograham@…>

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 Changed 3 years ago by Tim Graham <timograham@…>

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