summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/schema.py
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-12-24 15:55:57 +0100
committerClaude Paroz <claude@2xlibre.net>2014-12-27 12:52:44 +0100
commit2ceb10f3b02cbebad6ed908880f49a7c3e901d12 (patch)
treed79a50705b32da2fa33c37b8c54e99ce9108b599 /django/db/backends/mysql/schema.py
parent47182965465f47657cbab6858a6a8637cc32b2df (diff)
downloaddjango-2ceb10f3b02cbebad6ed908880f49a7c3e901d12.tar.gz
Fixed #14180 -- Prevented unneeded index creation on MySQL-InnoDB
Thanks zimnyx for the report and Simon Charette, Tim Graham for the reviews.
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)