﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32457	SeparateDatabaseAndState fails with RemoveField	Christian Bundy	nobody	"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:

1. Remove the field from the model and create a migration that removes the field from Django's state.
2. 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!"	Bug	closed	Migrations	3.1	Normal	invalid	database state remove field		Unreviewed	0	0	0	0	0	0
