summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-05-13 17:40:57 +0200
committerClaude Paroz <claude@2xlibre.net>2015-05-15 17:08:49 +0200
commit6a0d9f068f9986c8c05e689e67be7bc22c59efc6 (patch)
treeba2194311168b562dd0b5de19d78593b4d318357 /tests/schema
parent30e57038440d7785072088c10fef3ed6e71faba5 (diff)
[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.
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 44c1d1e9cc..1b8b02e01b 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -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