Skip to content

Commit 37d48d0

Browse files
committed
Fix drop fk condition
1 parent 965573a commit 37d48d0

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

mssql/schema.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,19 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
349349

350350
# Drop any FK constraints, we'll remake them later
351351
fks_dropped = set()
352-
if old_field.remote_field and old_field.db_constraint and (django_version >= (4, 2) and self._field_should_be_altered(
353-
old_field,
354-
new_field,
355-
ignore={"db_comment"},
356-
)):
352+
if (
353+
old_field.remote_field
354+
and old_field.db_constraint
355+
and (django_version < (4,2)
356+
or
357+
(django_version >= (4, 2)
358+
and self._field_should_be_altered(
359+
old_field,
360+
new_field,
361+
ignore={"db_comment"})
362+
)
363+
)
364+
):
357365
# Drop index, SQL Server requires explicit deletion
358366
if not hasattr(new_field, 'db_constraint') or not new_field.db_constraint:
359367
index_names = self._constraint_names(model, [old_field.column], index=True)

0 commit comments

Comments
 (0)