Skip to content

I get a KeyError when I run manage.py makemigrations --replace-all (...) #4

@CelestialGuru

Description

@CelestialGuru

I'm unable to follow the step where I makemigrations --replace-all.

Steps I took

Created a new branch, deleted ALL migrations and committed changes.

Created another branch. Used:

>>> from django.apps import apps
>>> print(" ".join(map(str, sorted({model._meta.app_label for model in apps.get_models()}))))
'accounts admin authtoken contenttypes sessions token (the rest are apps in my project)'

Ran

python manage.py makemigrations --replace-all --name replace_old_migration (everything from previous script)

All at once:

python \
   manage.py \
   makemigrations \
   --replace-all \
   --name replace_old_migrations \
   $(python manage.py shell -c "from django.apps import apps; print(' '.join(map(str, sorted({model._meta.app_label for model
in apps.get_models()}))))")

Error

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django_replace_migrations/management/commands/makemigrations.py", line 154, in handle
    loader.project_state(),
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/loader.py", line 324, in project_state
    return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
  File "/usr/local/lib/python3.6/site-packages/django/db/migrations/graph.py", line 315, in make_state
    project_state = self.nodes[node].mutate_state(project_state, preserve=False)
KeyError: ('contenttypes', '0001_initial')

The previous script is only for convenience. I manually wrote out the makemigrations line with all the app listed and I still got the same error. I removed each app that the key error was complaining about until I was down to like three apps before it happily ran.

Other strategies attempted

Even if I add if model._meta.app_label not in {'admin', 'auth', 'authtoken', 'contenttypes', 'sessions', 'token'} filter (apps which are not mine) I still get a KeyError, just with a different app.

Many of my apps depend on other apps, and many of those apps depend on each other.
Do I need to separate squashing into separate groups/batches? How would I tell which apps go in which group/batch?

Versions

Python: 3.6.8
Django: 2.2.1
django-replace-migrations: 0.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions