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

Fixed #26171 -- Made MySQL create an index on ForeignKeys with db_contraint=False.

Refactored "Prevented unneeded index creation on MySQL-InnoDB" (2ceb10f)
to avoid setting db_index=False.
This commit is contained in:
Aaron Elliot Ross
2016-06-28 14:22:20 +02:00
committed by Tim Graham
parent 5fe1c92250
commit 6bf7964023
4 changed files with 21 additions and 11 deletions

View File

@@ -62,7 +62,7 @@ class SchemaIndexesTests(TestCase):
def test_no_index_for_foreignkey(self):
"""
MySQL on InnoDB already creates indexes automatically for foreign keys.
(#14180).
(#14180). An index should be created if db_constraint=False (#26171).
"""
storage = connection.introspection.get_storage_engine(
connection.cursor(), ArticleTranslation._meta.db_table
@@ -70,4 +70,7 @@ class SchemaIndexesTests(TestCase):
if storage != "InnoDB":
self.skip("This test only applies to the InnoDB storage engine")
index_sql = connection.schema_editor()._model_indexes_sql(ArticleTranslation)
self.assertEqual(index_sql, [])
self.assertEqual(index_sql, [
'CREATE INDEX `indexes_articletranslation_99fb53c2` '
'ON `indexes_articletranslation` (`article_no_constraint_id`)'
])