@@ -602,9 +602,6 @@ def _ensure_all_fk_constraints(self, model):
602602 Ensure that foreign key constraints are properly created at the database level
603603 for ALL OBJECT type fields with ON DELETE CASCADE.
604604
605- NOTE: This method is deprecated for normal use - use _ensure_field_fk_constraint
606- for individual fields. This is kept for migration purposes only.
607-
608605 :param model: The model to ensure FK constraints for
609606 """
610607 # Query all OBJECT type fields for this CustomObjectType
@@ -1558,14 +1555,9 @@ def save(self, *args, **kwargs):
15581555 schema_editor .alter_field (model , old_field , model_field )
15591556
15601557 # Ensure FK constraints are properly created for OBJECT fields with CASCADE behavior
1561- # Only do this when:
1562- # 1. Creating a new OBJECT field, OR
1563- # 2. Updating an existing field where type changed to OBJECT, OR
1564- # 3. Updating an existing OBJECT field where related_object_type changed
15651558 should_ensure_fk = False
15661559 if self .type == CustomFieldTypeChoices .TYPE_OBJECT :
15671560 if self ._state .adding :
1568- # New OBJECT field - ensure FK constraint
15691561 should_ensure_fk = True
15701562 else :
15711563 # Existing field - check if type changed to OBJECT or related_object_type changed
@@ -1585,7 +1577,6 @@ def save(self, *args, **kwargs):
15851577 super ().save (* args , ** kwargs )
15861578
15871579 # Ensure FK constraints AFTER the transaction commits to avoid "pending trigger events" errors
1588- # We use transaction.on_commit() to ensure all deferred constraints are checked first
15891580 if should_ensure_fk :
15901581 def ensure_constraint ():
15911582 self .custom_object_type ._ensure_field_fk_constraint (model , self .name )
0 commit comments