diff options
| author | Ed Morley <emorley@mozilla.com> | 2016-12-01 15:54:58 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-12-01 12:25:37 -0500 |
| commit | 82ce55dbbe2d96e8b5d1fcb4a1d52b73e08e7929 (patch) | |
| tree | f747b6913889684a029a06b68c4df443f2425e8e /tests | |
| parent | 4074fa91452006890a878f0b6a1a25251461cf26 (diff) | |
[1.10.x] Fixed #27558 -- Prevented redundant index on InnoDB ForeignKey.
The MySQL backend overrides _field_should_be_indexed() so that it skips
index creation for ForeignKeys when using InnoDB.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/indexes/tests.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py index dfc503e15d..8db3adc66e 100644 --- a/tests/indexes/tests.py +++ b/tests/indexes/tests.py @@ -1,6 +1,8 @@ from unittest import skipUnless from django.db import connection +from django.db.models.deletion import CASCADE +from django.db.models.fields.related import ForeignKey from django.test import TestCase from .models import Article, ArticleTranslation, IndexTogetherSingleList @@ -74,3 +76,15 @@ class SchemaIndexesTests(TestCase): 'CREATE INDEX `indexes_articletranslation_99fb53c2` ' 'ON `indexes_articletranslation` (`article_no_constraint_id`)' ]) + + # The index also shouldn't be created if the ForeignKey is added after + # the model was created. + with connection.schema_editor() as editor: + new_field = ForeignKey(Article, CASCADE) + new_field.set_attributes_from_name('new_foreign_key') + editor.add_field(ArticleTranslation, new_field) + self.assertEqual(editor.deferred_sql, [ + 'ALTER TABLE `indexes_articletranslation` ' + 'ADD CONSTRAINT `indexes_articl_new_foreign_key_id_d27a9146_fk_indexes_article_id` ' + 'FOREIGN KEY (`new_foreign_key_id`) REFERENCES `indexes_article` (`id`)' + ]) |
