mirror of
https://github.com/django/django.git
synced 2025-10-25 14:46:09 +00:00
[1.8.x] Fixed #24757 -- Recreated MySQL index when needed during combined index removal
Thanks Thomas Recouvreux for the report and Tim Graham for the tests and
review.
Backport of ae635cc36 from master.
This commit is contained in:
@@ -1084,6 +1084,24 @@ class SchemaTests(TransactionTestCase):
|
||||
self.assertRaises(IntegrityError, UniqueTest.objects.create, year=2012, slug="foo")
|
||||
UniqueTest.objects.all().delete()
|
||||
|
||||
def test_unique_together_with_fk(self):
|
||||
"""
|
||||
Tests removing and adding unique_together constraints that include
|
||||
a foreign key.
|
||||
"""
|
||||
# Create the table
|
||||
with connection.schema_editor() as editor:
|
||||
editor.create_model(Author)
|
||||
editor.create_model(Book)
|
||||
# Ensure the fields are unique to begin with
|
||||
self.assertEqual(Book._meta.unique_together, ())
|
||||
# Add the unique_together constraint
|
||||
with connection.schema_editor() as editor:
|
||||
editor.alter_unique_together(Book, [], [['author', 'title']])
|
||||
# Alter it back
|
||||
with connection.schema_editor() as editor:
|
||||
editor.alter_unique_together(Book, [['author', 'title']], [])
|
||||
|
||||
def test_index_together(self):
|
||||
"""
|
||||
Tests removing and adding index_together constraints on a model.
|
||||
@@ -1127,6 +1145,24 @@ class SchemaTests(TransactionTestCase):
|
||||
),
|
||||
)
|
||||
|
||||
def test_index_together_with_fk(self):
|
||||
"""
|
||||
Tests removing and adding index_together constraints that include
|
||||
a foreign key.
|
||||
"""
|
||||
# Create the table
|
||||
with connection.schema_editor() as editor:
|
||||
editor.create_model(Author)
|
||||
editor.create_model(Book)
|
||||
# Ensure the fields are unique to begin with
|
||||
self.assertEqual(Book._meta.index_together, ())
|
||||
# Add the unique_together constraint
|
||||
with connection.schema_editor() as editor:
|
||||
editor.alter_index_together(Book, [], [['author', 'title']])
|
||||
# Alter it back
|
||||
with connection.schema_editor() as editor:
|
||||
editor.alter_index_together(Book, [['author', 'title']], [])
|
||||
|
||||
def test_create_index_together(self):
|
||||
"""
|
||||
Tests creating models with index_together already defined
|
||||
|
||||
Reference in New Issue
Block a user