1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

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.
This commit is contained in:
Daniel Patrick
2024-07-03 19:23:59 +01:00
committed by Sarah Boyce
parent e095c7612d
commit d12184fedc
2 changed files with 21 additions and 2 deletions

View File

@@ -1131,6 +1131,22 @@ class StateTests(SimpleTestCase):
self.assertIsNone(order_field.related_model)
self.assertIsInstance(order_field, models.PositiveSmallIntegerField)
def test_get_order_field_after_removed_order_with_respect_to_field(self):
new_apps = Apps()
class HistoricalRecord(models.Model):
_order = models.PositiveSmallIntegerField()
class Meta:
app_label = "migrations"
apps = new_apps
model_state = ModelState.from_model(HistoricalRecord)
model_state.options["order_with_respect_to"] = None
order_field = model_state.get_field("_order")
self.assertIsNone(order_field.related_model)
self.assertIsInstance(order_field, models.PositiveSmallIntegerField)
def test_manager_refer_correct_model_version(self):
"""
#24147 - Managers refer to the correct version of a