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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user