#35424: Migration autodetector fails when order_with_respect_to is removed, but 
an
_order field remains
------------------------------------+------------------------------------
     Reporter:  Stuart Attenborrow  |                    Owner:  nobody
         Type:  Bug                 |                   Status:  new
    Component:  Migrations          |                  Version:  4.2
     Severity:  Normal              |               Resolution:
     Keywords:                      |             Triage Stage:  Accepted
    Has patch:  0                   |      Needs documentation:  0
  Needs tests:  0                   |  Patch needs improvement:  0
Easy pickings:  1                   |                    UI/UX:  0
------------------------------------+------------------------------------
Changes (by Sarah Boyce):

 * stage:  Unreviewed => Accepted

Comment:

 Thank you for the report, managed to replicate on main
 Given an existing migrated model
 {{{#!python
 class Foo(models.Model):
     order = models.IntegerField(default=999999)

     class Meta:
         order_with_respect_to = "order"
 }}}
 when you change that model to
 {{{#!python
 class Foo(models.Model):
     _order = models.IntegerField(default=999999)

    class Meta:
         ordering = ("_order",)
 }}}
 that generates a migration like
 {{{#!python
 # Generated by Django 5.1 on 2024-05-03 12:02

 from django.db import migrations


 class Migration(migrations.Migration):

     dependencies = [
         ('app3', '0004_foo'),
     ]

     operations = [
         migrations.AlterModelOptions(
             name='foo',
             options={'ordering': ('_order',)},
         ),
         migrations.RenameField(
             model_name='foo',
             old_name='order',
             new_name='_order',
         ),
         migrations.AlterOrderWithRespectTo(
             name='foo',
             order_with_respect_to=None,
         ),
     ]
 }}}
 Which fails with `django.core.exceptions.FieldDoesNotExist: Foo has no
 field named 'order'`
 If you move `AlterOrderWithRespectTo` to be the first operation, this
 migration can be applied.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35424#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018f3e5bca15-6558df2a-7e61-4634-82de-a690adb4f26b-000000%40eu-central-1.amazonses.com.

Reply via email to