#24291: Migrations fail with unused swappable model
----------------------------+--------------------
     Reporter:  knbk        |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  master
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/24291>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/047.11edb0a52c6dbe2b8c9a6979da62c066%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to