Refs #32743 -- Fixed recreation of foreign key constraints when altering type of referenced primary key with MTI.

Follow up to 325d7710ce.
This commit is contained in:
Jordan Bae 2021-07-26 23:56:05 +09:00 committed by Mariusz Felisiak
parent 11879530a3
commit 3d9040a50b
3 changed files with 25 additions and 2 deletions

View file

@ -1551,10 +1551,32 @@ class OperationTests(OperationTestBase):
with connection.schema_editor() as editor:
operation.database_forwards(app_label, editor, project_state, new_state)
assertIdTypeEqualsMTIFkType()
if connection.features.supports_foreign_keys:
self.assertFKExists(
f'{app_label}_shetlandpony',
['pony_ptr_id'],
(f'{app_label}_pony', 'id'),
)
self.assertFKExists(
f'{app_label}_shetlandrider',
['pony_id'],
(f'{app_label}_shetlandpony', 'pony_ptr_id'),
)
# Reversal.
with connection.schema_editor() as editor:
operation.database_backwards(app_label, editor, new_state, project_state)
assertIdTypeEqualsMTIFkType()
if connection.features.supports_foreign_keys:
self.assertFKExists(
f'{app_label}_shetlandpony',
['pony_ptr_id'],
(f'{app_label}_pony', 'id'),
)
self.assertFKExists(
f'{app_label}_shetlandrider',
['pony_id'],
(f'{app_label}_shetlandpony', 'pony_ptr_id'),
)
@skipUnlessDBFeature('supports_foreign_keys')
def test_alter_field_reloads_state_on_fk_with_to_field_target_type_change(self):