Ticket #24757: 24757.diff

File 24757.diff, 1.2 KB (added by Tim Graham, 9 years ago)
  • tests/schema/tests.py

    diff --git a/tests/schema/tests.py b/tests/schema/tests.py
    index 6cfc30a..1777843 100644
    a b class SchemaTests(TransactionTestCase):  
    10841084        self.assertRaises(IntegrityError, UniqueTest.objects.create, year=2012, slug="foo")
    10851085        UniqueTest.objects.all().delete()
    10861086
     1087    def test_unique_together_with_fk(self):
     1088        """
     1089        Tests removing and adding unique_together constraints that include
     1090        a foreign key.
     1091        """
     1092        # Create the table
     1093        with connection.schema_editor() as editor:
     1094            editor.create_model(Author)
     1095            editor.create_model(Book)
     1096        # Ensure the fields are unique to begin with
     1097        self.assertEqual(Book._meta.unique_together, ())
     1098        # Add the unique_together constraint
     1099        with connection.schema_editor() as editor:
     1100            editor.alter_unique_together(Book, [], [['author', 'title']])
     1101        # Alter it back
     1102        with connection.schema_editor() as editor:
     1103            editor.alter_unique_together(Book, [['author', 'title']], [])
     1104
    10871105    def test_index_together(self):
    10881106        """
    10891107        Tests removing and adding index_together constraints on a model.
Back to Top