Changes between Initial Version and Version 2 of Ticket #37477
- Timestamp:
- Nov 5, 2026, 8:48:21 AM (3 weeks ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #37477
- Property Component Uncategorized → Migrations
-
Ticket #37477 – Description
initial v2 1 {{{#!text2 1 When a model is renamed, `makemigrations` can put operations on the new model name before the `RenameModel` operation. `migrate` then crashes with a `KeyError`. 3 2 … … 9 8 10 9 Starting point (migrated): 11 }}}12 10 13 11 {{{#!python … … 16 14 }}} 17 15 18 {{{#!text19 16 Changed to: 20 }}}21 17 22 18 {{{#!python … … 33 29 }}} 34 30 35 {{{#!text36 31 `makemigrations` ("Was the model shop.Author renamed to Writer? y") writes the operations in this order: 37 }}}38 32 39 33 {{{#!python … … 45 39 }}} 46 40 47 {{{#!text 41 48 42 `migrate` fails: 49 43 44 {{{#!text 50 45 File ".../django/db/migrations/state.py", line 183, in alter_model_options 51 46 model_state = self.models[app_label, model_name] 52 47 KeyError: ('shop', 'writer') 48 }}} 53 49 54 50 Without 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. … … 59 55 60 56 Tested on main (6.2 dev) with SQLite. 61 }}}