Roberto Roberto - 1 year ago 149
Python Question

Django migrations error KeyError: ('list', u'user')

I am trying to run

python migrate


python makemigrations

I got this error:

Running migrations:
No migrations to apply.
Traceback (most recent call last):
File "", line 10, in <module>
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/", line 353, in execute_from_command_line
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/", line 345, in execute
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/", line 399, in execute
output = self.handle(*args, **options)
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/commands/", line 183, in handle
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/db/migrations/", line 338, in project_state
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/db/migrations/", line 280, in make_state
project_state = self.nodes[node].mutate_state(project_state, preserve=False)
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/db/migrations/", line 88, in mutate_state
operation.state_forwards(self.app_label, new_state)
File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/db/migrations/operations/", line 547, in state_forwards
model_state = state.models[app_label, self.name_lower]
KeyError: ('list', u'user')

It happen after I pulled another version of my app from the git.

I don't have this error with the same code on the another machine.
I've tried to use
or to
to previous but this also doesn't help.

Cannot get how to solve it.

Answer Source

The problem was in migration files. While I was making commit into git somehow I've deleted one of the migration files, so the order was like 0001 0003 0004 without 0002. In the second migration file I've created a model named user.

The problem was that when I run python migrate django could not find the place where the model named user has been created (this model has been created in 0002 file).

I solved it by manually adding this code to the 0001 migration file:

            (...necessary fields...),
            'ordering': ('title',),
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download