[Django] #29224: Can not delete an index_together if there is a unique_together on the same fields

27 views
Skip to first unread message

Django

unread,
Mar 15, 2018, 12:16:44 PM3/15/18
to django-...@googlegroups.com
#29224: Can not delete an index_together if there is a unique_together on the same
fields
-------------------------------------+-------------------------------------
Reporter: Matthieu | Owner: nobody
Rigal |
Type: | Status: new
Uncategorized |
Component: Database | Version: 1.11
layer (models, ORM) |
Severity: Normal | Keywords: index
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Happens with Django 1.11.10

Steps to reproduce:
1) Create models with 2 fields, add 2 same fields to unique_together and
to index_together
2) Delete index_together -> Fail

It will fail at django/db/backends/base/schema.py, line 378, in
_delete_composed_index(), `ValueError: Found wrong number (2) of
constraints for` as this one will find two constraints, the `_uniq` and
the `_idx` one. No way to get out of this...

The worst in my case is that happened as I wanted to refactor my code to
use the "new" (Dj 1.11) Options.indexes feature. I am actually not
deleting the index, just the way it is declared in my code.

I think there are 2 different points here:
1) The deletion of index_together should be possible alone or made
coherent (migrations side?) with unique_together
2) Moving the declaration of an index should not result in an index re-
creation

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

Django

unread,
Mar 21, 2018, 8:37:35 PM3/21/18
to django-...@googlegroups.com
#29224: Migration crashes deleting an index_together if there is a unique_together
on the same fields
--------------------------------+------------------------------------
Reporter: Matthieu Rigal | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: index | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
* component: Database layer (models, ORM) => Migrations


Comment:

Reproduced on master at 623139b5d1bd006eac78b375bcaf5948e695c3c6.

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

Django

unread,
Jun 29, 2018, 1:00:08 PM6/29/18
to django-...@googlegroups.com
#29224: Migration crashes deleting an index_together if there is a unique_together
on the same fields

--------------------------------+------------------------------------
Reporter: Matthieu Rigal | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: index | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------

Comment (by Jeff):

I haven't looked under the hood on this yet, but could it be related to
the ordering of the operations generated for the mgiration? on first
inspection it feels like this and
[https://code.djangoproject.com/ticket/28862 #28862] could be caused by
the same/similar underlying problem in how `FieldRelatedOptionOperation`
subclasses ordering is handled in the migration `autodetector`'s migration
optimizer.

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

Django

unread,
Jun 29, 2018, 1:00:14 PM6/29/18
to django-...@googlegroups.com
#29224: Migration crashes deleting an index_together if there is a unique_together
on the same fields

--------------------------------+------------------------------------
Reporter: Matthieu Rigal | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: index | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Jeff):

* cc: Jeff (added)


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

Django

unread,
Apr 12, 2020, 6:23:35 PM4/12/20
to django-...@googlegroups.com
#29224: Migration crashes deleting an index_together if there is a unique_together
on the same fields
--------------------------------+-----------------------------------------
Reporter: Matthieu Rigal | Owner: David Wobrock
Type: Bug | Status: assigned

Component: Migrations | Version: 1.11
Severity: Normal | Resolution:
Keywords: index | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+-----------------------------------------
Changes (by David Wobrock):

* owner: nobody => David Wobrock
* status: new => assigned
* has_patch: 0 => 1


Comment:

PR https://github.com/django/django/pull/12708

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

Django

unread,
Apr 23, 2020, 6:30:04 AM4/23/20
to django-...@googlegroups.com
#29224: Migration crashes deleting an index_together if there is a unique_together

on the same fields
-------------------------------------+-------------------------------------
Reporter: Matthieu Rigal | Owner: David
| Wobrock
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: index | 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 felixxm):

* version: 1.11 => master
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29224#comment:5>

Django

unread,
Apr 23, 2020, 6:49:22 AM4/23/20
to django-...@googlegroups.com
#29224: Migration crashes deleting an index_together if there is a unique_together

on the same fields
-------------------------------------+-------------------------------------
Reporter: Matthieu Rigal | Owner: David
| Wobrock
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: index | 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 Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"533b208775620b8303b00583aaf011b4e81e6535" 533b2087]:
{{{
#!CommitTicketReference repository=""
revision="533b208775620b8303b00583aaf011b4e81e6535"
Fixed #29224 -- Fixed removing index_together indexes if exists
unique_together constraint on the same fields.
}}}

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

Reply all
Reply to author
Forward
0 new messages