summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAaron Elliot Ross <aaronelliotross@gmail.com>2016-06-28 14:22:20 +0200
committerTim Graham <timograham@gmail.com>2016-06-28 08:22:36 -0400
commit198128684bb0c47e9ea2900a92d192794d62791f (patch)
treea477fd5e531a5607496d8896c1ca8c4102c9010b /tests
parent5c04852455d7b08314da6d1c156819ff0dfbec3a (diff)
[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
Diffstat (limited to 'tests')
-rw-r--r--tests/indexes/models.py1
-rw-r--r--tests/indexes/tests.py7
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`)'
+ ])