Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…dbc-azure into OskarPersson-issue-92
  • Loading branch information
michiya committed Jan 28, 2018
2 parents 4cc8a0d + 9ab9c89 commit e85b10e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sql_server/pyodbc/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type,
# Drop any FK constraints, we'll remake them later
fks_dropped = set()
if old_field.remote_field and old_field.db_constraint:
# Drop index, SQL Server requires explicit deletion
if not new_field.db_constraint:
index_names = self._constraint_names(model, [old_field.column], index=True)
for index_name in index_names:
self.execute(self._delete_constraint_sql(self.sql_delete_index, model, index_name))

fk_names = self._constraint_names(model, [old_field.column], foreign_key=True)
if strict and len(fk_names) != 1:
raise ValueError("Found wrong number (%s) of foreign key constraints for %s.%s" % (
Expand Down

0 comments on commit e85b10e

Please sign in to comment.