summaryrefslogtreecommitdiff
path: root/django/db/backends/mysql/schema.py
diff options
context:
space:
mode:
authorMatjaz Gregoric <mtyaka@gmail.com>2021-08-12 09:52:24 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-08-20 10:30:02 +0200
commite9aa20e4e17aee7adcf52fcd3f445cd296fa9b7b (patch)
treed72508abeed1855d3b0a55979e3cff62abfffbf4 /django/db/backends/mysql/schema.py
parentbf5abf1bdcedb15e949db419c61eeec7c88414ea (diff)
downloaddjango-e9aa20e4e17aee7adcf52fcd3f445cd296fa9b7b.tar.gz
Optimized DatabaseSchemaEditor._field_should_be_indexed() on MySQL.
Diffstat (limited to 'django/db/backends/mysql/schema.py')
-rw-r--r--django/db/backends/mysql/schema.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/db/backends/mysql/schema.py b/django/db/backends/mysql/schema.py
index 39450dd50d..6402bc7145 100644
--- a/django/db/backends/mysql/schema.py
+++ b/django/db/backends/mysql/schema.py
@@ -107,7 +107,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
}, [effective_default])
def _field_should_be_indexed(self, model, field):
- create_index = super()._field_should_be_indexed(model, field)
+ if not super()._field_should_be_indexed(model, field):
+ return False
+
storage = self.connection.introspection.get_storage_engine(
self.connection.cursor(), model._meta.db_table
)
@@ -115,11 +117,10 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
# db_constraint=False because the index from that constraint won't be
# created.
if (storage == "InnoDB" and
- create_index and
field.get_internal_type() == 'ForeignKey' and
field.db_constraint):
return False
- return not self._is_limited_data_type(field) and create_index
+ return not self._is_limited_data_type(field)
def _delete_composed_index(self, model, fields, *args):
"""