Fixed #14180 -- Prevented unneeded index creation on MySQL-InnoDB

Thanks zimnyx for the report and Simon Charette, Tim Graham for
the reviews.
This commit is contained in:
Claude Paroz 2014-12-24 15:55:57 +01:00
parent 4718296546
commit 2ceb10f3b0
5 changed files with 42 additions and 9 deletions

View file

@ -5,7 +5,7 @@ from django.db import connection
from django.test import TestCase
from django.test.utils import IgnorePendingDeprecationWarningsMixin
from .models import Article, IndexTogetherSingleList
from .models import Article, ArticleTranslation, IndexTogetherSingleList
class CreationIndexesTests(IgnorePendingDeprecationWarningsMixin, TestCase):
@ -82,3 +82,17 @@ class SchemaIndexesTests(TestCase):
"""Test indexes are not created for related objects"""
index_sql = connection.schema_editor()._model_indexes_sql(Article)
self.assertEqual(len(index_sql), 1)
@skipUnless(connection.vendor == 'mysql', "This is a mysql-specific issue")
def test_no_index_for_foreignkey(self):
"""
MySQL on InnoDB already creates indexes automatically for foreign keys.
(#14180).
"""
storage = connection.introspection.get_storage_engine(
connection.cursor(), ArticleTranslation._meta.db_table
)
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, [])