Fixed #28051 -- Made migrations respect Index's name argument.
Thanks Marc Tamlyn for the report and Tim Graham for the review.
This commit is contained in:
parent
5d3b322dce
commit
d3cf75ec6f
|
@ -446,7 +446,8 @@ class ModelState:
|
||||||
elif name == "indexes":
|
elif name == "indexes":
|
||||||
indexes = [idx.clone() for idx in model._meta.indexes]
|
indexes = [idx.clone() for idx in model._meta.indexes]
|
||||||
for index in indexes:
|
for index in indexes:
|
||||||
index.set_name_with_model(model)
|
if not index.name:
|
||||||
|
index.set_name_with_model(model)
|
||||||
options['indexes'] = indexes
|
options['indexes'] = indexes
|
||||||
else:
|
else:
|
||||||
options[name] = model._meta.original_attrs[name]
|
options[name] = model._meta.original_attrs[name]
|
||||||
|
|
|
@ -9,4 +9,6 @@ Django 1.11.1 fixes several bugs in 1.11.
|
||||||
Bugfixes
|
Bugfixes
|
||||||
========
|
========
|
||||||
|
|
||||||
* ...
|
* Made migrations respect ``Index``’s ``name`` argument. If you created a
|
||||||
|
named index with Django 1.11, ``makemigrations`` will create a migration to
|
||||||
|
recreate the index with the correct name (:ticket:`28051`).
|
||||||
|
|
|
@ -1070,6 +1070,19 @@ class ModelStateTests(SimpleTestCase):
|
||||||
child1_state.options['indexes'][0].name = 'bar'
|
child1_state.options['indexes'][0].name = 'bar'
|
||||||
self.assertEqual(Child1._meta.indexes[0].name, 'migrations__name_b0afd7_idx')
|
self.assertEqual(Child1._meta.indexes[0].name, 'migrations__name_b0afd7_idx')
|
||||||
|
|
||||||
|
@isolate_apps('migrations')
|
||||||
|
def test_explicit_index_name(self):
|
||||||
|
class TestModel(models.Model):
|
||||||
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
app_label = 'migrations'
|
||||||
|
indexes = [models.indexes.Index(fields=['name'], name='foo_idx')]
|
||||||
|
|
||||||
|
model_state = ModelState.from_model(TestModel)
|
||||||
|
index_names = [index.name for index in model_state.options['indexes']]
|
||||||
|
self.assertEqual(index_names, ['foo_idx'])
|
||||||
|
|
||||||
|
|
||||||
class RelatedModelsTests(SimpleTestCase):
|
class RelatedModelsTests(SimpleTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue