Opened 4 years ago
Closed 4 years ago
#32457 closed Bug (invalid)
SeparateDatabaseAndState fails with RemoveField
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 field from 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.
Actual 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!
Change History (4)
comment:1 by , 4 years ago
Description: | modified (diff) |
---|
comment:2 by , 4 years ago
Description: | modified (diff) |
---|
comment:3 by , 4 years ago
Description: | modified (diff) |
---|
comment:4 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I'm not sure why you want to do this changes separately, but it's not a supported usage, see docs:
In
0002_remove_person_last_name
you removedPerson.last_name
field from the state soRemoveField()
cannot work anymore. You can try to remove it manually in0003_trigger_error
withRunSQL()
.For an example using
SeparateDatabaseAndState
, see Changing a ManyToManyField to use a through model.