﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24291	Migrations fail with unused swappable model	Marten Kenbeek	Marten Kenbeek	"An unused swappable model has no managers, but when trying to migrate the app containing that model, `django.db.migrations.state.ModelState.from_model` is called. That method expects the model to have at least a `_default_manager`. As this isn't the case, an `AttributeError` is raised:

{{{
File ""manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/home/s120374/projects/dev/django/django/core/management/__init__.py"", line 330, in execute_from_command_line
    utility.execute()
  File ""/home/s120374/projects/dev/django/django/core/management/__init__.py"", line 322, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/home/s120374/projects/dev/django/django/core/management/base.py"", line 350, in run_from_argv
    self.execute(*args, **cmd_options)
  File ""/home/s120374/projects/dev/django/django/core/management/base.py"", line 401, in execute
    output = self.handle(*args, **options)
  File ""/home/s120374/projects/dev/django/django/core/management/commands/migrate.py"", line 173, in handle
    ProjectState.from_apps(apps),
  File ""/home/s120374/projects/dev/django/django/db/migrations/state.py"", line 94, in from_apps
    model_state = ModelState.from_model(model)
  File ""/home/s120374/projects/dev/django/django/db/migrations/state.py"", line 348, in from_model
    default_manager_name = model._default_manager.name
AttributeError: type object 'Swappable' has no attribute '_default_manager'
}}}

The same happens when making a new migration using `makemigrations`, and when migrating an app that doesn't contain the swappable model. "	Bug	closed	Migrations	1.8alpha1	Release blocker	fixed		Markus Holtermann	Ready for checkin	1	0	0	0	0	0
