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

I'm trying to run

python manage.py migrate

or

python manage.py makemigrations

I got this error:

Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 183, in handle
    executor.loader.project_state(),
  File "/Users/rostunov/temp/venv/lib/python2.7/site-packages/django/db/migrations/loader.py", 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/graph.py", 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/migration.py", 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/models.py", line 547, in state_forwards
    model_state = state.models[app_label, self.name_lower]
KeyError: ('list', u'user')

This happens after I pulled a different version of my application from git.

I do not have this error with the same code on another computer. I tried to use --fakefrom zeroor to squashmigrationsto the previous one, but this also does not help.

It is impossible to decide how to solve it.

+14
source share
7 answers

The problem was in the migration files. While I was doing commit in git, I deleted one of the migration files, so the order was as 0001 0003 0004without 0002. In the second migration file, I created a model called user.

, python manage.py migrate django , ( 0002).

, 0001:

migrations.CreateModel(
        name='user',
        fields=[
            (...necessary fields...),
        ],
        options={
            'ordering': ('title',),
        },
    ),
+8

, db\migrations\operations\models.py KeyError PyCharm ().

-, . , makemigrations .

+19

, , , Model.py , , makemigrations. , squashmigrations , , . , - . .

+7

, . , "", "" , django_migrations. .

+3

. , Google:

(, )

, , ( ) , , . makemigrations/migrate

Django 2.0 PostgreSQL 9.6

, . JGED

: PostgreSQL

+2

@ceasaro, .

Django , . , Django .

makemigrations migrate, .

, .

+1

, . . , .

However, when I "squashmigrations", which fixed the problem. I answer here, so anyone who reaches this page can try this solution.

0
source

Source: https://habr.com/ru/post/1624998/


All Articles