mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
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:
parent
4718296546
commit
2ceb10f3b0
5 changed files with 42 additions and 9 deletions
|
@ -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, [])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue