[Django] #36632: AlterIndexTogether drops overlapping indexes

3 views
Skip to first unread message

Django

unread,
Sep 29, 2025, 8:23:15 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: mherrmann | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
1. Create a model with two index_together fields: `('a', 'b')`
2. Run `makemigrations`.
3. Add field `c` and change index_together to `(('a', 'b'), ('a', 'b',
'c'))`.
4. Run `makemigrations`.
5. Run `migrate`.

For at least SQLite, this silently drops the two-column index and only
produces the three-column index.

I am attaching code that can be used to reproduce the issue. To run it,
place all files in the same folder, `cd` into it and execute:

{{{
chmod +x steps.sh
./steps.sh
}}}

(This requires macOS or Linux. It should be easy to see how to execute the
steps on Windows.)

Executing `steps.sh` with Django 5 produces error

{{{
ValueError: Found wrong number (0) of indexes for polls_mymodel(a, b).
}}}

On the other hand, executing the script with Django 4 succeeds without any
errors.

(Please see the script for what I mean by "executing with Django 4/5".)

The script generates three migrations. And actually, the bug is already
there after the second migration. But the third migration highlights the
issue with an error message.

I am attaching script `show_indexes.py` that can be used to debug the
issue. It shows the indexes in the SQLite database. When `steps.sh` is
executed with Django 4 and without the third migration, then
`show_indexes.py` displays two indexes - one for two and one for three
columns. On the other hand, when `steps.sh` is executed with Django 5 (and
without the third migration), then `show_indexes.py` only shows one index,
for the three columns. `show_indexes.py` needs Django 4.
--
Ticket URL: <https://code.djangoproject.com/ticket/36632>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 29, 2025, 8:24:06 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "models_2.py" added.

Django

unread,
Sep 29, 2025, 8:24:06 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "models_1.py" added.

Django

unread,
Sep 29, 2025, 8:24:07 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "models_3.py" added.

Django

unread,
Sep 29, 2025, 8:24:08 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: mherrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 mherrmann):

* Attachment "show_indexes.py" added.

Django

unread,
Sep 29, 2025, 8:24:09 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "steps.sh" added.

Django

unread,
Sep 29, 2025, 8:25:56 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "steps.2.sh" added.

Django

unread,
Sep 29, 2025, 8:26:07 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "steps.sh" removed.

Django

unread,
Sep 29, 2025, 8:26:09 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "steps.2.sh" removed.

Django

unread,
Sep 29, 2025, 8:26:30 AM (2 days ago) Sep 29
to django-...@googlegroups.com
#36632: AlterIndexTogether drops overlapping indexes
-------------------------------------+-------------------------------------
Reporter: Michael Herrmann | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
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 Michael Herrmann):

* Attachment "steps.sh" added.
Reply all
Reply to author
Forward
0 new messages