schema.py 651 B

1234567891011121314
  1. from django.db.backends.mysql import schema as myschema
  2. class DatabaseSchemaEditor(myschema.DatabaseSchemaEditor):
  3. sql_delete_table = "DROP TABLE %(table)s"
  4. sql_delete_column = "ALTER TABLE %(table)s DROP COLUMN %(column)s"
  5. def remove_field(self, model, field):
  6. # Drop any Index, TiDB requires explicite deletion
  7. if field.db_index:
  8. idx_names = self._constraint_names(model, [field.column], index=True)
  9. for idx_name in idx_names:
  10. self.execute(self._delete_constraint_sql(self.sql_delete_index, model, idx_name))
  11. super(DatabaseSchemaEditor, self).remove_field(model, field)