I ran into a similar issue, where db\migrations\operations\models.py
was throwing a KeyError
after renaming a model through PyCharm’s refactoring (renaming).
Apparently the refactoring also took place in the migration file. When opening up the migration file and changing back to the original naming, the makemigrations
command worked fine.