Skip to content

Commit

Permalink
use str of field as index
Browse files Browse the repository at this point in the history
  • Loading branch information
ivissani committed Oct 13, 2020
1 parent e1c1954 commit 3c95a5e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sql_server/pyodbc/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,15 @@ def alter_db_table(self, model, old_db_table, new_db_table):

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

def _delete_deferred_unique_indexes_for_field(self, field_name):
deferred_statements = self._deferred_unique_indexes.get(field_name, [])
def _delete_deferred_unique_indexes_for_field(self, field):
deferred_statements = self._deferred_unique_indexes.get(str(field), [])
for stmt in deferred_statements:
if stmt in self.deferred_sql:
self.deferred_sql.remove(stmt)

def _add_deferred_unique_index_for_field(self, field, statement):
self._deferred_unique_indexes[str(field)].append(statement)

def _alter_field(self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False):
"""Actually perform a "physical" (non-ManyToMany) field update."""
Expand Down Expand Up @@ -660,7 +663,7 @@ def add_field(self, model, field):
model, [field], sql=self.sql_create_unique_null, suffix="_uniq"
)
self.deferred_sql.append(statement)
self._deferred_unique_indexes[field].append(statement)
self._add_deferred_unique_index_for_field(field, statement)

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

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

0 comments on commit 3c95a5e

Please sign in to comment.