django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

83 views
Skip to first unread message

su...@janakitech.com

unread,
Dec 23, 2014, 5:23:16 AM12/23/14
to django...@googlegroups.com
I have following model.

class CampaignTemp(models.Model):
    campaign_modules = Module.objects.filter(active=True)
    choices = ....
    ...
    ... # other fields 

I get following error when I try `python manage.py`.
...
File "/home/auser/aproject/src/apps/anapp/models.py", line 35, in CampaignTemp
    campaign_modules = Module.objects.filter(active=True)
...
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
...

The code was written for Django1.6 and is being ported to 1.7. Any help would be appreciated.

Jani Tiainen

unread,
Dec 23, 2014, 8:29:16 AM12/23/14
to django...@googlegroups.com
You're doing it wrong. You should never try to access data from database when
constructing models (or load modules) since there is no guarantee that "Module" model
is completely initialized and working properly.

Since you don't provide more details I assume that you try to have dynamic from Module to
fill choices. There are two fundamental problems first is what happens above and second
is that campaign_modules is only evaluated _once_ in lifetime of a CampaignTemp model. So
if you change active status of modules they're not reflected to that list.

You need to provide more context of your model so we can help with proper solution.

--

Jani Tiainen
Reply all
Reply to author
Forward
0 new messages