Wednesday, March 2, 2016

Re: Django 1.9 Apps aren't loaded yet

On Wed, Mar 02, 2016 at 08:20:44AM -0500, Larry Martell wrote:
> On Wed, Mar 2, 2016 at 7:37 AM, Michal Petrucha
> <michal.petrucha@koniiiik.org> wrote:
> > On Wed, Mar 02, 2016 at 07:05:53AM -0500, Larry Martell wrote:
> >> I am developing a django app. I had the basic site running, but I had
> >> not yet created any models. I created a model, and now the server
> >> fails to start with "Apps aren't loaded yet"
> >>
> >> traceback below. Anyone know what I am doing wrong?
> >
> > The problem is that one of your applications (foo.app.scripts) imports
> > models in its top-level __init__.py. This is not supported; for an
> > explanation, you can read
> > https://docs.djangoproject.com/en/1.9/ref/applications/#how-applications-are-loaded
>
> Thanks you very much for the quick reply. Is there some workaround for
> this? What version was this issued introduced in? This code works in
> 1.5.

This is a result of making the initialization process of Django
explicit in 1.7. The correct way of fixing errors like this is to
untangle your imports, and remove anything that depends on models from
top-level __init__.py in your all your application packages. You want
to draw a boundary around all code that uses models, and make sure
that none of it is imported before django.setup() has finished.

For a quick and dirty workaround, you can always move the model import
statements into the definitions of functions that require it; that
way, the import is not executed until the function itself is called.

Good luck,

Michal

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20160302143450.GB960%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment