Skip to content

Commit

Permalink
Fixed #24757 -- Reverted "Prevented unneeded index creation on MySQL-…
Browse files Browse the repository at this point in the history
…InnoDB"

This reverts commit 2ceb10f (refs #14180).
  • Loading branch information
timgraham committed May 13, 2015
1 parent ca51c55 commit 065861b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
12 changes: 0 additions & 12 deletions django/db/backends/mysql/schema.py
Expand Up @@ -50,18 +50,6 @@ def add_field(self, model, field):
'column': self.quote_name(field.column),
}, [effective_default])

def _model_indexes_sql(self, model):
storage = self.connection.introspection.get_storage_engine(
self.connection.cursor(), model._meta.db_table
)
if storage == "InnoDB":
for field in model._meta.local_fields:
if field.db_index and not field.unique and field.get_internal_type() == "ForeignKey":
# Temporary setting db_index to False (in memory) to disable
# index creation for FKs (index automatically created by MySQL)
field.db_index = False
return super(DatabaseSchemaEditor, self)._model_indexes_sql(model)

def _alter_column_type_sql(self, table, old_field, new_field, new_type):
# Keep null property of old field, if it has changed, it will be handled separately
if old_field.null:
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/1.8.2.txt
Expand Up @@ -25,3 +25,6 @@ Bugfixes
pointing to :class:`~django.db.models.UUIDField` and inheritance on models
with ``UUIDField`` primary keys work correctly (:ticket:`24698`,
:ticket:`24712`).

* Added back MySQL index creation for foreign keys when using the InnoDB
storage engine due to problems when dropping other indexes (:ticket:`24757`).
2 changes: 2 additions & 0 deletions docs/releases/1.8.txt
Expand Up @@ -286,6 +286,8 @@ Database backends

* The MySQL backend no longer creates explicit indexes for foreign keys when
using the InnoDB storage engine, as MySQL already creates them automatically.
This change was reverted in :doc:`1.8.2 </releases/1.8.2>` because it
created problems when dropping other indexes without this index.

* The Oracle backend no longer defines the ``connection_persists_old_columns``
feature as ``True``. Instead, Oracle will now include a cache busting clause
Expand Down
16 changes: 1 addition & 15 deletions tests/indexes/tests.py
Expand Up @@ -3,7 +3,7 @@
from django.db import connection
from django.test import TestCase

from .models import Article, ArticleTranslation, IndexTogetherSingleList
from .models import Article, IndexTogetherSingleList


class SchemaIndexesTests(TestCase):
Expand Down Expand Up @@ -59,17 +59,3 @@ def test_postgresql_virtual_relation_indexes(self):
"""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, [])

0 comments on commit 065861b

Please sign in to comment.