From d12184fedcd586e2c399ea40abe4bf865ebc87a6 Mon Sep 17 00:00:00 2001 From: Daniel Patrick Date: Wed, 3 Jul 2024 19:23:59 +0100 Subject: Fixed #35424 -- Checked order_with_respect_to is available when migrating _order fields. Migrations would crash following the removal of an order_with_respect_to field from a model and the addition of an _order field. --- django/db/migrations/state.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index 42a2c80a5e..e13de5ba6f 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -761,8 +761,11 @@ class ModelState: return self.name.lower() def get_field(self, field_name): - if field_name == "_order": - field_name = self.options.get("order_with_respect_to", field_name) + if ( + field_name == "_order" + and self.options.get("order_with_respect_to") is not None + ): + field_name = self.options["order_with_respect_to"] return self.fields[field_name] @classmethod -- cgit v1.3