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
--
Ticket URL: <https://code.djangoproject.com/ticket/26034>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* severity: Normal => Release blocker
* needs_better_patch: => 0
* needs_tests: => 0
* version: 1.9 => 1.8
* needs_docs: => 0
* stage: Unreviewed => Accepted
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:1>
* component: Database layer (models, ORM) => Migrations
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:2>
Comment (by charettes):
i wonder if this could be related to #25694.
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:3>
* owner: nobody => timgraham
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:4>
Comment (by timgraham):
[https://github.com/django/django/pull/5947 PR] (have to double check a
few things tomorrow, so not checking 'has patch' yet)
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"56aaae58a746eb39d5e92ba60f59f4c750a8e1a8" 56aaae58]:
{{{
#!CommitTicketReference repository=""
revision="56aaae58a746eb39d5e92ba60f59f4c750a8e1a8"
Fixed #26034 -- Fixed incorrect index handling on PostgreSQL on
Char/TextField with unique=True and db_index=True.
Thanks Simon Charette for review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"3d324b9614afa1e9b391b30f6f21d2f65fa8ac90" 3d324b9]:
{{{
#!CommitTicketReference repository=""
revision="3d324b9614afa1e9b391b30f6f21d2f65fa8ac90"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:9>
Comment (by Tim Graham <timograham@…>):
In [changeset:"f8c3d38c2d26f99ca620d76a0d88b69eeeb88c2c" f8c3d38c]:
{{{
#!CommitTicketReference repository=""
revision="f8c3d38c2d26f99ca620d76a0d88b69eeeb88c2c"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"497b5d6feee5b7947231bd0ae6edf833773b6cce" 497b5d6]:
{{{
#!CommitTicketReference repository=""
revision="497b5d6feee5b7947231bd0ae6edf833773b6cce"
Refs #26034 -- Added another case fixed by this ticket to release notes.
Thanks Shai Berger for the report.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"5e8685c1b14e94e3f540ac1d68b61e71dcc27517" 5e8685c]:
{{{
#!CommitTicketReference repository=""
revision="5e8685c1b14e94e3f540ac1d68b61e71dcc27517"
Refs #26034 -- Added another case fixed by this ticket to release notes.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:12>
Comment (by Tim Graham <timograham@…>):
In [changeset:"4aec49d015a24ddd893567d2cd2682e1dc1dc107" 4aec49d]:
{{{
#!CommitTicketReference repository=""
revision="4aec49d015a24ddd893567d2cd2682e1dc1dc107"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:13>
Comment (by Tim Graham <timograham@…>):
In [changeset:"7b6ab2885e800ed25570d78d3241c25d6a49cd4a" 7b6ab28]:
{{{
#!CommitTicketReference repository=""
revision="7b6ab2885e800ed25570d78d3241c25d6a49cd4a"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:14>
Comment (by Tim Graham <timograham@…>):
In [changeset:"d47f6d75ef67dbd18abf2bb927753f739a9c117d" d47f6d75]:
{{{
#!CommitTicketReference repository=""
revision="d47f6d75ef67dbd18abf2bb927753f739a9c117d"
Refs #26034 -- Corrected a schema test to work with the correct field
state.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:15>
Comment (by Tim Graham <timograham@…>):
In [changeset:"5c04852455d7b08314da6d1c156819ff0dfbec3a" 5c048524]:
{{{
#!CommitTicketReference repository=""
revision="5c04852455d7b08314da6d1c156819ff0dfbec3a"
[1.10.x] Refs #26034 -- Corrected a schema test to work with the correct
field state.
Backport of d47f6d75ef67dbd18abf2bb927753f739a9c117d from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:16>
Comment (by Tim Graham <timograham@…>):
In [changeset:"54c0dea22ee11da9822fc217f108e878647f299e" 54c0dea]:
{{{
#!CommitTicketReference repository=""
revision="54c0dea22ee11da9822fc217f108e878647f299e"
[1.9.x] Refs #26034 -- Corrected a schema test to work with the correct
field state.
Backport of d47f6d75ef67dbd18abf2bb927753f739a9c117d from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:17>