mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
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.
This commit is contained in:
parent
0eaef8e527
commit
ae635cc365
4 changed files with 70 additions and 18 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue