Django manage.py runserver得到AppRegistryNotReady:模型尚未加载

时间:2016-07-26 12:46:55

标签: python django

我在使用manage.py runserver从命令行运行django时遇到了问题。

几个月前,Django 1.5使用相同的代码。

今天我想再次获取代码并运行Django 1.8.3和python2.7.10。

现在,这里得到了错误:

Traceback (most recent call last):
  File "manage.py", line 29, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/media/wni/study/workspace4320151111/weichun/mytheme/models.py", line 8, in <module>
    from mezzanine.pages.models import Page
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/pages/models.py", line 34, in <module>
    class Page(BasePage):
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/core/models.py", line 350, in __new__
    return super(OrderableBase, cls).__new__(cls, name, bases, attrs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 298, in __new__
    new_class.add_to_class(field.name, copy.deepcopy(field))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 226, in contribute_to_class
    super(KeywordsField, self).contribute_to_class(cls, name)
  File "/media/wni/study/workspace4320151111/weichun/mezzanine/generic/fields.py", line 84, in contribute_to_class
    cls._meta.get_fields_with_model()]:
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 56, in wrapper
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 432, in get_fields_with_model
    return [self._map_model(f) for f in self.get_fields()]
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 740, in get_fields
    return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 802, in _get_fields
    all_fields = self._relation_tree
  File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 709, in _relation_tree
    return self._populate_directed_relation_graph()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/options.py", line 681, in _populate_directed_relation_graph
    all_models = self.apps.get_models(include_auto_created=True)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/lru_cache.py", line 101, in wrapper
    result = user_function(*args, **kwds)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 168, in get_models
    self.check_models_ready()
  File "/usr/local/lib/python2.7/dist-packages/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.

任何人都知道如何修复它?

感谢。

韦斯利

1 个答案:

答案 0 :(得分:0)

我认为您需要更改wsgi.py文件,因为您需要更换不同版本的Django。

import os
import sys

from django.core.handlers.wsgi import WSGIHandler

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

并尝试评论在settings.py中导入的所有第三方应用程序。

1] ./manage.py runserver将使用你的wsgi.py,但看起来你顶部显示的堆栈跟踪不包含wsgi文件。因此,错误发生在加载wsgi文件之前。

2]这可能是您的Django设置的问题。例如,可以在不存在的目录中记录文件名。

3]或检查this