Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet
--
Music by Eric Matyas
https://www.soundimage.org
Track title: RPG Blues Looping
--
Chapters
00:00 Question
01:07 Accepted answer (Score 61)
01:49 Answer 2 (Score 239)
02:08 Answer 3 (Score 58)
03:10 Answer 4 (Score 19)
03:59 Thank you
--
Full question
https://stackoverflow.com/questions/2553...
Question links:
[registration]: https://bitbucket.org/ubernostrum/django.../
Accepted answer links:
[these folks]: https://stackoverflow.com/a/26636758/487...
Answer 2 links:
[this answer]: https://stackoverflow.com/a/25244833/977...
Answer 3 links:
[source]: https://github.com/django/django/blob/st...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django
#avk47
ANSWER 1
Score 239
Running these commands solved my problem (credit to this answer):
import django
django.setup()
However I'm not sure why I need this. Comments would be appreciated.
ACCEPTED ANSWER
Score 61
This is what solved it for us and these folks:
Our project started with Django 1.4, we went to 1.5 and then to 1.7. Our wsgi.py looked like this:
import os
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = WSGIHandler()
When I updated to the 1.7 style WSGI handler:
import os
from django.core.wsgi import get_wsgi_application
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()
Everything works now.
ANSWER 3
Score 58
The issue is in your registration app. It seems django-registration calls get_user_module() in models.py at a module level (when models are still being loaded by the application registration process). This will no longer work:
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
I'd change this models file to only call get_user_model() inside methods (and not at module level) and in FKs use something like:
user = ForeignKey(settings.AUTH_USER_MODEL)
BTW, the call to django.setup() shouldn't be required in your manage.py file, it's called for you in execute_from_command_line. (source)
ANSWER 4
Score 19
Just encountered the same issue. The problem is because of django-registration incompatible with django 1.7 user model.
A simple fix is to change these lines of code, at your installed django-registration module::
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
to::
from django.conf import settings
try:
from django.contrib.auth import get_user_model
User = settings.AUTH_USER_MODEL
except ImportError:
from django.contrib.auth.models import User
Mine is at .venv/local/lib/python2.7/site-packages/registration/models.py (virtualenv)