#33586: Applying RunPython backward results in ValueError when involved models are
referenced through multiple foreign keys
-------------------------------+------------------------------------
Reporter: Jeremy Poulin | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Comment (by Jacob Walls):
From the hint on #36161, I was able to solve this in an affected project
like:
{{{#!diff
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index 9e9cc58fae..2eecb640bf 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -410,10 +410,7 @@ class ProjectState:
except LookupError:
pass
else:
- if delay:
-
related_models.update(get_related_models_tuples(rel_model))
- else:
-
related_models.update(get_related_models_recursive(rel_model))
+
related_models.update(get_related_models_recursive(rel_model))
# Include the model itself
related_models.add((app_label, model_name))
}}}
Notice the comment just above this says "For all direct related models
recursively get all related models." So, with this proposal, we really
''would'' be getting all recursive models.
Does this look promising?
--
Ticket URL: <
https://code.djangoproject.com/ticket/33586#comment:36>