Changes between Initial Version and Version 2 of Ticket #37477


Ignore:
Timestamp:
Nov 5, 2026, 8:48:21 AM (3 weeks ago)
Author:
Sarah Boyce
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #37477

    • Property Component Uncategorized → Migrations
  • Ticket #37477 – Description

    initial v2  
    1 {{{#!text
    21When a model is renamed, `makemigrations` can put operations on the new model name before the `RenameModel` operation. `migrate` then crashes with a `KeyError`.
    32
    … …  
    98
    109Starting point (migrated):
    11 }}}
    1210
    1311{{{#!python
    … …  
    1614}}}
    1715
    18 {{{#!text
    1916Changed to:
    20 }}}
    2117
    2218{{{#!python
    … …  
    3329}}}
    3430
    35 {{{#!text
    3631`makemigrations` ("Was the model shop.Author renamed to Writer? y") writes the operations in this order:
    37 }}}
    3832
    3933{{{#!python
    … …  
    4539}}}
    4640
    47 {{{#!text
     41
    4842`migrate` fails:
    4943
     44{{{#!text
    5045    File ".../django/db/migrations/state.py", line 183, in alter_model_options
    5146        model_state = self.models[app_label, model_name]
    5247    KeyError: ('shop', 'writer')
     48}}}
    5349
    5450Without the new `Book` model the order is correct. I also see `AddIndex` and `AddConstraint` on the renamed model emitted before `RenameModel` in the same situation.
    … …  
    5955
    6056Tested on main (6.2 dev) with SQLite.
    61 }}}
Back to Top