Refs #26709 -- Added 'model' argument to SchemaEditor.add/remove_index()

This removes the dependency of the Index class on its model attribute
when a name is passed to it.

Thanks to Markush for discussions.
This commit is contained in:
Akshesh 2016-07-06 22:27:17 +05:30 committed by Tim Graham
parent 3410820460
commit 52442898e7
4 changed files with 20 additions and 18 deletions

View file

@ -1455,13 +1455,12 @@ class SchemaTests(TransactionTestCase):
self.assertNotIn('title', self.get_indexes(Author._meta.db_table))
# Add the index
index = Index(fields=['name'], name='author_title_idx')
index.model = Author
with connection.schema_editor() as editor:
editor.add_index(index)
editor.add_index(Author, index)
self.assertIn('name', self.get_indexes(Author._meta.db_table))
# Drop the index
with connection.schema_editor() as editor:
editor.remove_index(index)
editor.remove_index(Author, index)
self.assertNotIn('name', self.get_indexes(Author._meta.db_table))
def test_indexes(self):