diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/schema/tests.py | 36 |
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 |
