1
0
mirror of https://github.com/django/django.git synced 2025-10-26 07:06:08 +00:00

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

@@ -849,8 +849,8 @@ class BaseDatabaseSchemaEditor:
self.execute(self._create_fk_sql(model, new_field, "_fk_%(to_table)s_%(to_column)s"))
# Rebuild FKs that pointed to us if we previously had to drop them
if drop_foreign_keys:
for rel in new_field.model._meta.related_objects:
if _is_relevant_relation(rel, new_field) and rel.field.db_constraint:
for _, rel in rels_to_update:
if rel.field.db_constraint:
self.execute(self._create_fk_sql(rel.related_model, rel.field, "_fk"))
# Does it have check constraints we need to add?
if old_db_params['check'] != new_db_params['check'] and new_db_params['check']: