From 198128684bb0c47e9ea2900a92d192794d62791f Mon Sep 17 00:00:00 2001 From: Aaron Elliot Ross Date: Tue, 28 Jun 2016 14:22:20 +0200 Subject: [1.10.x] 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. Backport of 6bf7964023487f2a352084e74aca27aecb354d6c from master --- tests/indexes/models.py | 1 + tests/indexes/tests.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/indexes/models.py b/tests/indexes/models.py index b348f0365c..dc384ab489 100644 --- a/tests/indexes/models.py +++ b/tests/indexes/models.py @@ -19,6 +19,7 @@ class CurrentTranslation(models.ForeignObject): class ArticleTranslation(models.Model): article = models.ForeignKey('indexes.Article', models.CASCADE) + article_no_constraint = models.ForeignKey('indexes.Article', models.CASCADE, db_constraint=False) language = models.CharField(max_length=10, unique=True) content = models.TextField() diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py index 6e27130f63..dfc503e15d 100644 --- a/tests/indexes/tests.py +++ b/tests/indexes/tests.py @@ -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`)' + ]) -- cgit v1.3