KeyError: ('', '') when making migrations cannot be resolved

Asked 2 years ago, Updated 2 years ago, 124 views

I am developing a web system at Python 3, Django.

We are developing it by checking the operation locally and then deploying it to a remote server.

If there is a change in the model class, makemigratinons, migrate will be required on the remote server, but the following error message will appear when makingmigration occurs:

KeyError: ('admin_csv', 'prefcityno')

If you look into this error, I think that 'prefcityno' could not be found in 'admin_csv'.

I think the possible causes are makemigrations and how to execute maigrate in the local and remote environments.
In the local environment, we repeated makemigratins and migrates several times until the desired movement, checked the operation, and then migrated only once out of 5 to 6 files that were deployed to the remote location.

I responded because there was an error when I was conflicting, but I think the contents were bad.I deleted files (such as 0001_initial.py) and then merged them.

After that, even if you delete the remote database table, delete the migrations file, and then makeemigratins, KeyError: ('admin_csv', 'prefcityno') occurs.

'admin_csv' is the app directory that contains models.py where you make changes and get errors.
'prefcityno' is the name used during development in the local environment and is not included in the final deployed code.

I'm worried that it might be an error at a very deep place.
Could you tell me the solution to this error?

The hierarchy of files, etc., is as follows:

project
-- accounts
-- admin_csv
---- migrations
---- __init__.py
---- ---- admin.py
---- ---- apps.py
---- ---- models.py
---- ---- tests.py
---- ---- views.py
-- project
-- app
-- static
-- -- manage.py
env

$python3 manage.py makemigrations The following error messages are detailed:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File"/home/app/venv/lib/python 3.7/site-packages/django/core/management/_init__.py", line 401, in execute_from_command_line
    utility.execute()
  File"/home/app/venv/lib/python 3.7/site-packages/django/core/management/_init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File"/home/app/venv/lib/python 3.7/site-packages/django/core/management/base.py", line328, in run_from_argv
    self.execute(*args,**cmd_options)
  File"/home/app/venv/lib/python 3.7/site-packages/django/core/management/base.py", line 369, in execute
    output=self.handle(*args,**options)
  File"/home/app/venv/lib/python 3.7/site-packages/django/core/management/base.py", line83, inwrapped
    res=handle_func(*args,**kwargs)
  File"/home/app/venv/lib/python 3.7/site-packages/django/core/management/commands/makemigrations.py", line 141, in handle
    loader.project_state(),
  File"/home/app/venv/lib/python 3.7/site-packages/django/db/migrations/loader.py", line324, in project_state
    return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
  File"/home/app/venv/lib/python 3.7/site-packages/django/db/migrations/graph.py", line 315, in make_state
    project_state=self.nodes[node].mute_state(project_state, preserve=False)
  File"/home/app/venv/lib/python 3.7/site-packages/django/db/migrations/migration.py", line87, in mute_state
    operation.state_forwards(self.app_label, new_state)
  File"/home/app/venv/lib/python 3.7/site-packages/django/db/migrations/operations/models.py", line256, state_forwards
    state.remove_model (app_label, self.name_lower)
  File"/home/app/venv/lib/python 3.7/site-packages/django/db/migrations/state.py", line 99, in remove_model
    del self.models [app_label, model_name ]
KeyError: ('admin_csv', 'prefcityno')

Run Environment
Python: 3.7.5
Django: 2.2.2
PostgreSQL: 12.1

python python3 django

2022-09-30 21:45

1 Answers

The error disappeared and makemigrations was created.The reason was that the remote server had a file of past migrations.

I thought it was deleted and deployed on a local project and it was configured as it was, but in the past, it was necessary to manually delete the files.

This post was posted as a community wiki based on @tio's comments.


2022-09-30 21:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.