diff options
Diffstat (limited to 'tests/schema')
| -rw-r--r-- | tests/schema/tests.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 410a52b646..9b40a43523 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -241,6 +241,27 @@ class SchemaTests(TransactionTestCase): editor.alter_field(Book, old_field, new_field, strict=True) self.assertForeignKeyExists(Book, 'author_id', 'schema_tag') + @skipUnlessDBFeature('can_create_inline_fk') + def test_inline_fk(self): + # Create some tables. + with connection.schema_editor() as editor: + editor.create_model(Author) + editor.create_model(Book) + editor.create_model(Note) + self.assertForeignKeyNotExists(Note, 'book_id', 'schema_book') + # Add a foreign key from one to the other. + with connection.schema_editor() as editor: + new_field = ForeignKey(Book, CASCADE) + new_field.set_attributes_from_name('book') + editor.add_field(Note, new_field) + self.assertForeignKeyExists(Note, 'book_id', 'schema_book') + # Creating a FK field with a constraint uses a single statement without + # a deferred ALTER TABLE. + self.assertFalse([ + sql for sql in (str(statement) for statement in editor.deferred_sql) + if sql.startswith('ALTER TABLE') and 'ADD CONSTRAINT' in sql + ]) + @skipUnlessDBFeature('supports_foreign_keys') def test_char_field_with_db_index_to_fk(self): # Create the table |
