1
0
mirror of https://github.com/django/django.git synced 2025-10-30 09:06:13 +00:00

Fixed #14180 -- Prevented unneeded index creation on MySQL-InnoDB

Thanks zimnyx for the report and Simon Charette, Tim Graham for
the reviews.
This commit is contained in:
Claude Paroz
2014-12-24 15:55:57 +01:00
parent 4718296546
commit 2ceb10f3b0
5 changed files with 42 additions and 9 deletions

View File

@@ -51,3 +51,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
'table': self.quote_name(model._meta.db_table),
'column': self.quote_name(field.column),
}, [effective_default])
def _model_indexes_sql(self, model):
storage = self.connection.introspection.get_storage_engine(
self.connection.cursor(), model._meta.db_table
)
if storage == "InnoDB":
for field in model._meta.local_fields:
if field.db_index and not field.unique and field.get_internal_type() == "ForeignKey":
# Temporary setting db_index to False (in memory) to disable
# index creation for FKs (index automatically created by MySQL)
field.db_index = False
return super(DatabaseSchemaEditor, self)._model_indexes_sql(model)