Skip to content

Commit 6fac90c

Browse files
authored
add logic to include deleting _meta.indexes to _delete_indexes (#292)
1 parent 1827555 commit 6fac90c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mssql/schema.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
313313
if (old_is_auto and not new_is_auto) or (not old_is_auto and new_is_auto):
314314
raise NotImplementedError("the backend doesn't support altering from %s to %s." %
315315
(old_field.get_internal_type(), new_field.get_internal_type()))
316-
316+
317317
# Drop any FK constraints, we'll remake them later
318318
fks_dropped = set()
319319
if old_field.remote_field and old_field.db_constraint:
@@ -788,11 +788,23 @@ def _delete_indexes(self, model, old_field, new_field):
788788
if old_field.column in columns:
789789
index_columns.append(columns)
790790

791+
for index in model._meta.indexes:
792+
columns = [model._meta.get_field(field).column for field in index.fields]
793+
if old_field.column in columns:
794+
index_columns.append(columns)
795+
791796
for fields in model._meta.unique_together:
792797
columns = [model._meta.get_field(field).column for field in fields]
793798
if old_field.column in columns:
794799
index_columns.append(columns)
795800
if index_columns:
801+
# remove duplicates first
802+
temp = []
803+
for columns in index_columns:
804+
if columns not in temp:
805+
temp.append(columns)
806+
index_columns = temp
807+
796808
for columns in index_columns:
797809
index_names = self._constraint_names(model, columns, index=True)
798810
for index_name in index_names:

0 commit comments

Comments
 (0)