Skip to content

Router fails on migrations which contain deleted models #73

Description

@M1ha-Shvn

Hy. In one of migrations I have model, that has been deleted in later migrations and doesn't exist for now. When I do migrate, I get this error:

  File "/home/sergei/venv36/lib/python3.6/site-packages/django/apps/config.py", line 163, in get_model
    return self.models[model_name.lower()]
KeyError: 'clickhousecollapsemodelupdate'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/sergei/.pycharm_helpers/pycharm/django_manage.py", line 43, in <module>
    run_module(manage_file, None, '__main__', True)
  File "/usr/lib/python3.6/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/vagrant/cqapi/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django_sharding_library/management/commands/migrate.py", line 21, in handle
    super(Command, self).handle(*args, **options)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 95, in database_forwards
    if self.allow_migrate_model(schema_editor.connection.alias, model):
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/migrations/operations/base.py", line 115, in allow_migrate_model
    return router.allow_migrate_model(connection_alias, model)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/utils.py", line 311, in allow_migrate_model
    model=model,
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/db/utils.py", line 300, in allow_migrate
    allow = method(db, app_label, **hints)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django_sharding_library/router.py", line 157, in allow_migrate
    raise exception
  File "/home/sergei/venv36/lib/python3.6/site-packages/django_sharding_library/router.py", line 152, in allow_migrate
    model = app.get_model(model_name)
  File "/home/sergei/venv36/lib/python3.6/site-packages/django/apps/config.py", line 166, in get_model
    "App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'utils' doesn't have a 'ClickHouseCollapseModelUpdate' model.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions