Skip to content

Commit b35ccc6

Browse files
committed
Revert "Remove deprecated meta.index_together field"
This reverts commit b1e2a16.
1 parent b1e2a16 commit b35ccc6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

mssql/schema.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ def alter_unique_together(self, model, old_unique_together, new_unique_together)
291291
def _model_indexes_sql(self, model):
292292
"""
293293
Return a list of all index SQL statements (field indexes,
294-
Meta.indexes) for the specified model.
294+
index_together, Meta.indexes) for the specified model.
295295
"""
296296
if not model._meta.managed or model._meta.proxy or model._meta.swapped:
297297
return []
298298
output = []
299299
for field in model._meta.local_fields:
300300
output.extend(self._field_indexes_sql(model, field))
301301

302-
for field_names in model._meta.indexes:
302+
for field_names in model._meta.index_together:
303303
fields = [model._meta.get_field(field) for field in field_names]
304304
output.append(self._create_index_sql(model, fields, suffix="_idx"))
305305

@@ -792,7 +792,7 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
792792
if old_field.db_index and new_field.db_index:
793793
index_columns.append([old_field])
794794
else:
795-
for fields in model._meta.indexes:
795+
for fields in model._meta.index_together:
796796
columns = [model._meta.get_field(field) for field in fields]
797797
if old_field.column in [c.column for c in columns]:
798798
index_columns.append(columns)
@@ -917,7 +917,7 @@ def _delete_indexes(self, model, old_field, new_field):
917917
index_columns.append([old_field.column])
918918
elif old_field.null != new_field.null:
919919
index_columns.append([old_field.column])
920-
for fields in model._meta.indexes:
920+
for fields in model._meta.index_together:
921921
columns = [model._meta.get_field(field).column for field in fields]
922922
if old_field.column in columns:
923923
index_columns.append(columns)
@@ -1322,7 +1322,7 @@ def create_model(self, model):
13221322
model, field, field_type, field.db_comment
13231323
)
13241324
)
1325-
# Add any field index and indexes's (deferred as SQLite3 _remake_table needs it)
1325+
# Add any field index and index_together's (deferred as SQLite3 _remake_table needs it)
13261326
self.deferred_sql.extend(self._model_indexes_sql(model))
13271327
self.deferred_sql = list(set(self.deferred_sql))
13281328

testapp/tests/test_indexes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class TestCorrectIndexes(TestCase):
7878
def test_correct_indexes_exist(self):
7979
"""
8080
Check there are the correct number of indexes for each field after all migrations
81-
by comparing what the model says (e.g. `db_index=True` / `indexes` etc.)
81+
by comparing what the model says (e.g. `db_index=True` / `index_together` etc.)
8282
with the actual constraints found in the database.
8383
This acts as a general regression test for issues such as:
8484
- duplicate index created (e.g. https://github.com/microsoft/mssql-django/issues/77)
@@ -115,9 +115,9 @@ def test_correct_indexes_exist(self):
115115
expected_index_causes = []
116116
if field.db_index:
117117
expected_index_causes.append('db_index=True')
118-
for field_names in model_cls._meta.indexes:
118+
for field_names in model_cls._meta.index_together:
119119
if field.name in field_names:
120-
expected_index_causes.append(f'indexes[{field_names}]')
120+
expected_index_causes.append(f'index_together[{field_names}]')
121121
if field._unique and field.null:
122122
# This is implemented using a (filtered) unique index (not a constraint) to get ANSI NULL behaviour
123123
expected_index_causes.append('unique=True & null=True')

0 commit comments

Comments
 (0)