* `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.
* type: Uncategorized => New feature
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:1>
* cc: akki (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:2>
* cc: anr (removed)
* cc: andrewgodwin (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:3>
* cc: anr (removed)
* cc: andrewgodwin (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:3>
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>
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>
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>
* cc: Adam (Chainz) Johnson (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:7>
* cc: rvteja92 (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:8>
* 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>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:10>
* 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>
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:12>
* 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>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:14>
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>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:16>
* 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>
* needs_better_patch: 0 => 1
Comment:
It's blocked by #33710.
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:18>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:19>
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>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:21>
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>
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>
* status: assigned => closed
* resolution: => fixed
* stage: Ready for checkin => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/27064#comment:24>