Fixed #30108 -- Allowed adding foreign key constraints in the same statement that adds a field.

This commit is contained in:
Dan Tao 2019-01-18 22:17:26 -06:00 committed by Tim Graham
parent 9a0cc54524
commit 738faf9da2
9 changed files with 69 additions and 20 deletions

View file

@ -226,11 +226,9 @@ class SchemaIndexesMySQLTests(TransactionTestCase):
new_field.set_attributes_from_name('new_foreign_key')
editor.add_field(ArticleTranslation, new_field)
field_created = True
self.assertEqual([str(statement) for statement in editor.deferred_sql], [
'ALTER TABLE `indexes_articletranslation` '
'ADD CONSTRAINT `indexes_articletrans_new_foreign_key_id_d27a9146_fk_indexes_a` '
'FOREIGN KEY (`new_foreign_key_id`) REFERENCES `indexes_article` (`id`)'
])
# No deferred SQL. The FK constraint is included in the
# statement to add the field.
self.assertFalse(editor.deferred_sql)
finally:
if field_created:
with connection.schema_editor() as editor: