Skip to content

Commit 9ab9c89

Browse files
committed
Delete index when db_constraint is changed to False
1 parent 4df37f3 commit 9ab9c89

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sql_server/pyodbc/schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
6666
# Drop any FK constraints, we'll remake them later
6767
fks_dropped = set()
6868
if old_field.remote_field and old_field.db_constraint:
69+
if not new_field.db_constraint:
70+
index_names = self._constraint_names(model, [old_field.column], index=True)
71+
for index_name in index_names:
72+
self.execute(self._delete_constraint_sql(self.sql_delete_index, model, index_name))
73+
6974
fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
7075
if strict and len(fk_names) != 1:
7176
raise ValueError("Found wrong number (%s) of foreign key constraints for %s.%s" % (

0 commit comments

Comments
 (0)