Skip to content

Commit 3c95a5e

Browse files
committed
use str of field as index
1 parent e1c1954 commit 3c95a5e

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

sql_server/pyodbc/schema.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,15 @@ def alter_db_table(self, model, old_db_table, new_db_table):
240240

241241
return super().alter_db_table(model, old_db_table, new_db_table)
242242

243-
def _delete_deferred_unique_indexes_for_field(self, field_name):
244-
deferred_statements = self._deferred_unique_indexes.get(field_name, [])
243+
def _delete_deferred_unique_indexes_for_field(self, field):
244+
deferred_statements = self._deferred_unique_indexes.get(str(field), [])
245245
for stmt in deferred_statements:
246246
if stmt in self.deferred_sql:
247247
self.deferred_sql.remove(stmt)
248248

249+
def _add_deferred_unique_index_for_field(self, field, statement):
250+
self._deferred_unique_indexes[str(field)].append(statement)
251+
249252
def _alter_field(self, model, old_field, new_field, old_type, new_type,
250253
old_db_params, new_db_params, strict=False):
251254
"""Actually perform a "physical" (non-ManyToMany) field update."""
@@ -660,7 +663,7 @@ def add_field(self, model, field):
660663
model, [field], sql=self.sql_create_unique_null, suffix="_uniq"
661664
)
662665
self.deferred_sql.append(statement)
663-
self._deferred_unique_indexes[field].append(statement)
666+
self._add_deferred_unique_index_for_field(field, statement)
664667

665668
# Check constraints can go on the column SQL here
666669
db_params = field.db_parameters(connection=self.connection)
@@ -768,7 +771,7 @@ def create_model(self, model):
768771
model, [field], sql=self.sql_create_unique_null, suffix="_uniq"
769772
)
770773
self.deferred_sql.append(statement)
771-
self._deferred_unique_indexes[field].append(statement)
774+
self._add_deferred_unique_index_for_field(field, statement)
772775

773776
# Check constraints can go on the column SQL here
774777
db_params = field.db_parameters(connection=self.connection)

0 commit comments

Comments
 (0)