From 76d8a92faacb58744f29972bd3afa9e9d149ce38 Mon Sep 17 00:00:00 2001 From: Sicong Jia Date: Fri, 23 Jul 2021 10:01:00 -0700 Subject: [PATCH] Revert changes that drop indexes without recreate Issue #14 This change cause 'migrations.test_operations.OperationTests.test_rename_model_with_m2m' to fail, so skipped for now, it'll be fixed in the future. --- mssql/schema.py | 15 --------------- testapp/settings.py | 1 + 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/mssql/schema.py b/mssql/schema.py index 774c1a38..8b24e98d 100644 --- a/mssql/schema.py +++ b/mssql/schema.py @@ -244,17 +244,6 @@ def _db_table_delete_constraint_sql(self, template, db_table, name): include='' ) - def alter_db_table(self, model, old_db_table, new_db_table): - index_names = self._db_table_constraint_names(old_db_table, index=True) - for index_name in index_names: - self.execute(self._db_table_delete_constraint_sql(self.sql_delete_index, old_db_table, index_name)) - - index_names = self._db_table_constraint_names(new_db_table, index=True) - for index_name in index_names: - self.execute(self._db_table_delete_constraint_sql(self.sql_delete_index, new_db_table, index_name)) - - return super().alter_db_table(model, old_db_table, new_db_table) - 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.""" @@ -356,9 +345,6 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type, self.execute(self._delete_constraint_sql(self.sql_delete_check, model, constraint_name)) # Have they renamed the column? if old_field.column != new_field.column: - # remove old indices - self._delete_indexes(model, old_field, new_field) - self.execute(self._rename_field_sql(model._meta.db_table, old_field, new_field, new_type)) # Rename all references to the renamed column. for sql in self.deferred_sql: @@ -422,7 +408,6 @@ def _alter_field(self, model, old_field, new_field, old_type, new_type, actions = [(", ".join(sql), sum(params, []))] # Apply those actions for sql, params in actions: - self._delete_indexes(model, old_field, new_field) self.execute( self.sql_alter_column % { "table": self.quote_name(model._meta.db_table), diff --git a/testapp/settings.py b/testapp/settings.py index 18aadf41..31969eb8 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -189,6 +189,7 @@ 'dbshell.tests.DbshellCommandTestCase.test_command_missing', 'schema.tests.SchemaTests.test_char_field_pk_to_auto_field', 'datetimes.tests.DateTimesTests.test_21432', + 'migrations.test_operations.OperationTests.test_rename_model_with_m2m', # JSONFields 'model_fields.test_jsonfield.TestQuerying.test_has_key_list',