diff options
| author | Aaron Elliot Ross <aaronelliotross@gmail.com> | 2016-06-28 14:22:20 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-28 08:22:20 -0400 |
| commit | 6bf7964023487f2a352084e74aca27aecb354d6c (patch) | |
| tree | f5769cf125b037d5b10fe90d3ca60521e68f0198 /tests | |
| parent | 5fe1c92250017110430c7c2153cfd8776e4c7064 (diff) | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/indexes/models.py | 1 | ||||
| -rw-r--r-- | tests/indexes/tests.py | 7 |
2 files changed, 6 insertions, 2 deletions
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`)' + ]) |
