[Django] #26535: Possible bug - when migrating and removing unique constraint.

12 views
Skip to first unread message

Django

unread,
Apr 24, 2016, 5:12:07 AM4/24/16
to django-...@googlegroups.com
#26535: Possible bug - when migrating and removing unique constraint.
-------------------------------+--------------------
Reporter: jenlu | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Possible bug - when migrating and removing unique constraint.

Postgres 9.4.1 / 9.5.7 + Django 1.9.5 + psycopg 2.6.1

——

My setup is models/database representing sports events, and with
competitors in different events.

Each competitor in different sports has for their model/class:

class Meta:
unique_together = ('event', 'number')

i.e. ensure a unique starting number in an event, now we are relaxing
(removing this constraint)
this but having issues when migrating.

The above is represented in postgress as a UNIQUE constraint
and in all models.py the above constraint is as-above — but in pg it is
represented as

(i) UNIQUE (event_id, number)

and sometimes as...

(ii) UNIQUE (number, event_id)

…and now when doing migration - for all tables where it is represented as
(i) everything
goes well, but in tables where (ii) the following error:

File "/Users/XXX/.virtualenvs/ssi195_2711/lib/python2.7/site-
packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state,
project_state)
File "/Users/XXX/.virtualenvs/ssi195_2711/lib/python2.7/site-
packages/django/db/migrations/operations/models.py", line 359, in
database_forwards
getattr(new_model._meta, self.option_name, set()),
File "/Users/XXX/.virtualenvs/ssi195_2711/lib/python2.7/site-
packages/django/db/backends/base/schema.py", line 318, in
alter_unique_together
self._delete_composed_index(model, fields, {'unique': True},
self.sql_delete_unique)
File "/Users/XXX/.virtualenvs/ssi195_2711/lib/python2.7/site-
packages/django/db/backends/base/schema.py", line 347, in
_delete_composed_index
", ".join(columns),
ValueError: Found wrong number (0) of constraints for
match_ppc_ppccompetitor(event_id, number)

So seems to need to do some migrations manually and no biggie - but yet
strange and unsure if Django or pg issue….

/ Jens

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

Django

unread,
Apr 25, 2016, 10:51:12 AM4/25/16
to django-...@googlegroups.com
#26535: Possible bug - when migrating and removing unique constraint.
-------------------------------+--------------------------------------

Reporter: jenlu | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

New description:

——

(i) UNIQUE (event_id, number)

and sometimes as...

(ii) UNIQUE (number, event_id)

/ Jens

--

Comment:

Could you provide a sample project that reproduces the issue?

--
Ticket URL: <https://code.djangoproject.com/ticket/26535#comment:1>

Django

unread,
Apr 26, 2016, 7:26:40 AM4/26/16
to django-...@googlegroups.com
#26535: Possible bug - when migrating and removing unique constraint.
-------------------------------+--------------------------------------

Reporter: jenlu | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

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

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

Comment (by jenlu):

Hi, did some test but unable to reproduce in my ‘current’ setup - it
always generates a
uniqueness constraint that can be removed.

Seems like my oldest models did generate one ordering in pg
(UNIQUE(number, event_id)
whereas models added later on did generate the different ordering in pq
(UNIQUE(event_id,
number) and this later have no problems to be removed/relaxed.

Workaround for me was just to DROP the constraint and add a new one with
same arguments
but in different order..

/ Jens

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

Django

unread,
Apr 26, 2016, 8:06:16 AM4/26/16
to django-...@googlegroups.com
#26535: Possible bug - when migrating and removing unique constraint.
-------------------------------+--------------------------------------
Reporter: jenlu | Owner: nobody
Type: Uncategorized | Status: closed
Component: Migrations | Version: 1.9
Severity: Normal | Resolution: worksforme
Keywords: | Triage Stage: Unreviewed

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

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

* status: new => closed
* resolution: => worksforme


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

Reply all
Reply to author
Forward
0 new messages