[Django] #27064: Implement RenameIndex in a backwards compatible way

20 views
Skip to first unread message

Django

unread,
Aug 14, 2016, 9:02:43 PM8/14/16
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------------------+------------------------
Reporter: MarkusH | Owner: nobody
Type: Uncategorized | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 1 | Needs tests: 1
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
In order to eventually deprecate `index_together` we need a way to deal
with old projects that have unnamed indexes. This proves to be a non-
trivial problem. Andrew and I came up with these things to consider.

* `RenameIndex(model, new_name, old_name=None, old_fields=None)` where
exactly one of `old_name` and `old_field` is given (`old_name ^
old_fields`)
* If the old_name is given we use `RENAME INDEX` if available
* Otherwise look at the state and drop existing indexes and create new the
index with new name
* On MySQL (or other DBs) that don't support `RENAME INDEX`, provide SQL
query to look up index name from information_schema by field names and
pass in to `DROP INDEX`.
* If more than one index is found while identifying with field names,
migrations must error out with an `AmbiguityError`
* If the autodetector finds an old, unnamed index and a new, named one
matching field signature, issue a `RenameIndex` operation
* For backwards operations with unnamed old indexes, `RenameIndex` is a
noop.

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

Django

unread,
Aug 14, 2016, 9:03:03 PM8/14/16
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------+------------------------------------
Reporter: MarkusH | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by MarkusH):

* type: Uncategorized => New feature


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

Django

unread,
Aug 19, 2016, 6:29:23 AM8/19/16
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------+------------------------------------
Reporter: MarkusH | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by MarkusH):

* cc: akki (added)


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

Django

unread,
Aug 19, 2016, 6:29:43 AM8/19/16
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------+------------------------------------
Reporter: MarkusH | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by MarkusH):

* cc: anr (removed)
* cc: andrewgodwin (added)


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

Django

unread,
Aug 19, 2016, 6:30:25 AM8/19/16
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------+------------------------------------
Reporter: MarkusH | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by MarkusH):

* cc: anr (removed)
* cc: andrewgodwin (added)

Django

unread,
Sep 18, 2016, 12:51:52 AM9/18/16
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------+------------------------------------
Reporter: MarkusH | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by akki):

Is there a reason why we cannot just simply deprecate `index_together`.

My understanding is that the models file of the app will get modified from
this

{{{#!python

class Meta:
index_together = (('a', 'b'))
}}}

to this

{{{#!python

class Meta:
indexes = [models.Index(fields=['a', 'b'])]
}}}

and everything should work fine (or not? Am I missing something?)

I need some help to see where `RenameIndex` comes into picture here.

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

Django

unread,
Nov 12, 2016, 1:44:00 PM11/12/16
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------------+------------------------------------
Reporter: Markus Holtermann | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by Markus Holtermann):

I just noticed that I actually never commented here. So, the reason is
explained here: https://code.djangoproject.com/ticket/27236#comment:9

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

Django

unread,
Apr 9, 2020, 1:13:50 AM4/9/20
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------------+------------------------------------
Reporter: Markus Holtermann | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by felixxm):

> On MySQL (or other DBs) that don't support RENAME INDEX, provide SQL


query to look up index name from information_schema by field names and

pass in to DROP INDEX.

`RENAME INDEX` is now supported on
[https://dev.mysql.com/doc/refman/5.7/en/alter-table.html MySQL 5.7+] and
[https://mariadb.com/kb/en/alter-table/#rename-indexkey MariaDB 10.5.2+].

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

Django

unread,
Apr 9, 2020, 5:06:21 PM4/9/20
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------------+------------------------------------
Reporter: Markus Holtermann | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by Adam (Chainz) Johnson):

* cc: Adam (Chainz) Johnson (added)


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

Django

unread,
Jul 13, 2020, 1:08:14 PM7/13/20
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-----------------------------------+------------------------------------
Reporter: Markus Holtermann | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by rvteja92):

* cc: rvteja92 (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:8>

Django

unread,
May 4, 2022, 11:18:55 AM5/4/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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 David Wobrock):

* status: new => assigned
* cc: David Wobrock (added)
* needs_tests: 1 => 0
* owner: nobody => David Wobrock
* needs_docs: 1 => 0
* has_patch: 0 => 1


Comment:

Hi there,

I tried to tackle this change in this
[https://github.com/django/django/pull/15651 PR].

Feel free to review it!
And maybe we'll be able to deprecate `index_together` in a next major
release, as we wanted to do here
https://code.djangoproject.com/ticket/27236 a few years back :)

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:9>

Django

unread,
May 9, 2022, 5:45:15 AM5/9/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

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

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:10>

Django

unread,
May 9, 2022, 12:53:05 PM5/9/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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 David Wobrock):

* needs_better_patch: 1 => 0


Comment:

Integrated the review comments and split the PR into 2 parts:
1. Adding the RenameIndex operation
https://github.com/django/django/pull/15677
2. Using the RenameIndex in the autodetector
https://github.com/django/django/pull/15651

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:11>

Django

unread,
May 11, 2022, 6:21:28 AM5/11/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:12>

Django

unread,
May 11, 2022, 9:21:29 AM5/11/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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 David Wobrock):

* needs_better_patch: 1 => 0

* needs_tests: 1 => 0


Comment:

Integrated review changes into the first PR
[https://github.com/django/django/pull/15677 implementing RenameIndex
operation].

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:13>

Django

unread,
May 12, 2022, 4:57:04 AM5/12/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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 Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:14>

Django

unread,
May 12, 2022, 3:31:28 PM5/12/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"eacd4977f6a4bb038e82796ba79a2f61bae330c6" eacd4977]:
{{{
#!CommitTicketReference repository=""
revision="eacd4977f6a4bb038e82796ba79a2f61bae330c6"
Refs #27064 -- Added RenameIndex migration operation.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:15>

Django

unread,
May 12, 2022, 3:32:25 PM5/12/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

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

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:16>

Django

unread,
May 13, 2022, 3:52:06 PM5/13/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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 David Wobrock):

* needs_better_patch: 1 => 0


Comment:

Rebased [https://github.com/django/django/pull/15651 PR], ready for some
review again :)
Even if it (most probably) won't be included to the coming 4.1 release.

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:17>

Django

unread,
May 16, 2022, 1:39:05 AM5/16/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

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

* needs_better_patch: 0 => 1


Comment:

It's blocked by #33710.

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:18>

Django

unread,
May 16, 2022, 5:18:40 AM5/16/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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 Mariusz Felisiak):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:19>

Django

unread,
May 16, 2022, 12:53:01 PM5/16/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

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

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

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"c6cec3c2d287b5d2bd36d9c3002712ae89b5ab17" c6cec3c2]:
{{{
#!CommitTicketReference repository=""
revision="c6cec3c2d287b5d2bd36d9c3002712ae89b5ab17"
Refs #27064 -- Made migrations generate RenameIndex operations when
renaming Meta.indexes.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:20>

Django

unread,
May 17, 2022, 1:05:18 AM5/17/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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 Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:21>

Django

unread,
May 17, 2022, 2:25:17 AM5/17/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"a098cde9683a560bfc4b22f9b2581cf8cedc7dab" a098cde9]:
{{{
#!CommitTicketReference repository=""
revision="a098cde9683a560bfc4b22f9b2581cf8cedc7dab"
Refs #27064 -- Refactored out
MigrationAutodetector.create_renamed_fields().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:22>

Django

unread,
May 17, 2022, 2:25:17 AM5/17/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | 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
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"97f124f39e363bf518fbe428320bdee63d56f8e0" 97f124f]:
{{{
#!CommitTicketReference repository=""
revision="97f124f39e363bf518fbe428320bdee63d56f8e0"
Refs #27064 -- Made migrations generate RenameIndex operations when moving
indexes from index_together to Meta.indexes.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:23>

Django

unread,
May 17, 2022, 2:43:34 AM5/17/22
to django-...@googlegroups.com
#27064: Implement RenameIndex in a backwards compatible way
-------------------------------------+-------------------------------------
Reporter: Markus Holtermann | Owner: David
| Wobrock
Type: New feature | Status: closed
Component: Migrations | Version: dev
Severity: Normal | Resolution: fixed
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 Mariusz Felisiak):

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


* stage: Ready for checkin => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:24>

Reply all
Reply to author
Forward
0 new messages