Opened 4 years ago
Last modified 4 years ago
#32457 closed Bug
SeparateDatabaseAndState fails with RemoveField — at Version 1
Reported by: | Christian Bundy | Owned by: | nobody |
---|---|---|---|
Component: | Migrations | Version: | 3.1 |
Severity: | Normal | Keywords: | database state remove field |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Hi. We're doing multi-stage migrations with a blue-green deployment model, and currently bumping into an error. I think this is a small problem with a quick fix. The goal was to remove a field with three separate changes:
- Remove the model and create a migration that removes the field from Django's state.
- Create a migration that removes the field from the database.
I've reproduced the error in a Git repository here, with the above migrations:
https://github.com/christianbundy/django-bug-remove-field/tree/main/example/migrations
Expected behavior: The migration succeeds.
Action behavior:
File "/usr/local/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 158, in state_forwards old_field = model_state.fields.pop(self.name) KeyError: 'last_name'
Relevant Django code: https://github.com/django/django/blob/d02d60eb0f032c9395199fb73c6cd29ee9bb2646/django/db/migrations/operations/fields.py#L162
Is there some other way that I should be making this change, or is this a bug in Django?
Thanks for the help!