summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/mysql/schema.py')
-rw-r--r--django/db/backends/mysql/schema.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py
index 573779a49b..697490e888 100644
--- a/django/db/backends/mysql/schema.py
+++ b/django/db/backends/mysql/schema.py
@@ -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)