Django 1.7 throws django.core.exceptions.AppRegistryNotReady:模型尚未加载

问题:

这是我的Windows系统的追溯。

Traceback (most recent call last):
  File "D:\AMD\workspace\steelrumors\manage.py", line 9, in <module>
    django.setup()
  File "D:\AMD\Django\django-django-4c85a0d\django\__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "D:\AMD\Django\django-django-4c85a0d\django\apps\registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "D:\AMD\Django\django-django-4c85a0d\django\apps\config.py", line 197, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "C:\Python27\lib\site-packages\registration\models.py", line 15, in <module>
    User = get_user_model()
  File "D:\AMD\Django\django-django-4c85a0d\django\contrib\auth\__init__.py", line 135, in get_user_model
    return django_apps.get_model(settings.AUTH_USER_MODEL)
  File "D:\AMD\Django\django-django-4c85a0d\django\apps\registry.py", line 199, in get_model
    self.check_models_ready()
  File "D:\AMD\Django\django-django-4c85a0d\django\apps\registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

我的manage.py看起来像这样:

import os
import sys
import django

if __name__ == "__main__":

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "steelrumors.settings")
    django.setup()
    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

当我尝试使用Django 1.7中的registration应用程序时,我收到此错误

回答:

这是为我们解决的,these folks
我们的项目从Django 1.4开始,我们去了1.5,然后到了1.7。我们的wsgi.py看起来像这样:

import os

from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = WSGIHandler()

当我更新到1.7风格的WSGI处理程序:

import os

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()

一切工作现在

 
 
Code问答: http://codewenda.com/topics/python/
Stackoverflow: Django 1.7 throws django.core.exceptions.AppRegistryNotReady: Models aren’t loaded yet

*转载请注明本文链接以及stackoverflow的英文链接

发表评论

电子邮件地址不会被公开。 必填项已用*标注

66 − 62 =