[Django] #26034: Altering CharFields to have both db_index=True and unique=True crashes on postgresql

7 views
Skip to first unread message

Django

unread,
Jan 4, 2016, 8:06:09 AM1/4/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
----------------------------------------------+--------------------
Reporter: kaedroho | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/26034>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 4, 2016, 8:10:28 AM1/4/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------

Reporter: kaedroho | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Jan 4, 2016, 11:19:32 AM1/4/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
---------------------------------+------------------------------------

Reporter: kaedroho | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by charettes):

* component: Database layer (models, ORM) => Migrations


--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:2>

Django

unread,
Jan 4, 2016, 11:25:34 AM1/4/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
---------------------------------+------------------------------------

Reporter: kaedroho | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by charettes):

i wonder if this could be related to #25694.

--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:3>

Django

unread,
Jan 7, 2016, 7:20:22 PM1/7/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
---------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: assigned

Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by timgraham):

* owner: nobody => timgraham
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:4>

Django

unread,
Jan 7, 2016, 8:11:51 PM1/7/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
---------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------

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>

Django

unread,
Jan 8, 2016, 9:47:35 AM1/8/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
---------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:6>

Django

unread,
Jan 8, 2016, 11:46:08 AM1/8/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------

Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: assigned
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26034#comment:7>

Django

unread,
Jan 8, 2016, 2:16:37 PM1/8/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Jan 8, 2016, 2:32:42 PM1/8/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jan 8, 2016, 2:59:00 PM1/8/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jan 25, 2016, 8:34:49 AM1/25/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jan 25, 2016, 8:36:21 AM1/25/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jan 25, 2016, 8:37:31 AM1/25/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jan 25, 2016, 8:37:55 AM1/25/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 27, 2016, 12:13:28 PM6/27/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 27, 2016, 12:17:36 PM6/27/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 27, 2016, 12:19:47 PM6/27/16
to django-...@googlegroups.com
#26034: Altering CharFields to have both db_index=True and unique=True crashes on
postgresql
-------------------------------------+-------------------------------------
Reporter: kaedroho | Owner: timgraham
Type: Bug | Status: closed
Component: Migrations | Version: 1.8
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages