gpt4 book ai didi

Django 1.7 升级错误 : AppRegistryNotReady: Models aren't loaded yet

转载 作者:行者123 更新时间:2023-12-03 13:08:57 38 4
gpt4 key购买 nike

我正在尝试将项目从 Django 1.6 升级到 1.7。到目前为止,我已经创建了一个具有所有相同安装的新 virtualenv,并将 Django 版本升级到新版本。我需要从 South 升级,但这样做时出错,所以我想我最初只是尝试 runserver,但我收到以下错误:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/Name/Dev/tps/products/models.py", line 127, in <module>
watson.register(Product.objects.exclude(productimage=None))
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/query.py", line 698, in exclude
return self._filter_or_exclude(True, *args, **kwargs)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/query.py", line 707, in _filter_or_exclude
clone.query.add_q(~Q(*args, **kwargs))
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1287, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1314, in _add_q
current_negated=current_negated, connector=connector)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1138, in build_filter
lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1076, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1339, in names_to_path
field, model, direct, m2m = opts.get_field_by_name(name)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/options.py", line 416, in get_field_by_name
cache = self.init_name_map()
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/options.py", line 445, in init_name_map
for f, model in self.get_all_related_m2m_objects_with_model():
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/options.py", line 563, in get_all_related_m2m_objects_with_model
cache = self._fill_related_many_to_many_cache()
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/db/models/options.py", line 577, in _fill_related_many_to_many_cache
for klass in self.apps.get_models():
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/utils/lru_cache.py", line 101, in wrapper
result = user_function(*args, **kwds)
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-packages/django/apps/registry.py", line 168, in get_models
self.check_models_ready()
File "/Users/Name/.virtualenvs/test17/lib/python2.7/site-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.

任何想法可能导致错误以及如何解决它?

最佳答案

当我将我的 django 项目模板更新到 1.7 时,我收到了这个错误。改变的一件事是 wsgi.py 文件,因此需要一些更新。这是我的回溯:

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 93, in handle
self.handle_request(listener, req, client, addr)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 134, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/handlers/wsgi.py", line 168, in __call__
self.load_middleware()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/handlers/base.py", line 46, in load_middleware
mw_instance = mw_class()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/middleware/locale.py", line 23, in __init__
for url_pattern in get_resolver(None).url_patterns:
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/urlresolvers.py", line 372, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/core/urlresolvers.py", line 366, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/kpmteam/staging/site/kpm/urls.py", line 7, in <module>
admin.autodiscover()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/contrib/admin/__init__.py", line 23, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/utils/module_loading.py", line 67, in autodiscover_modules
for app_config in apps.get_app_configs():
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/home/kpmteam/staging/deploys/20141029-115625/site/lib/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
AppRegistryNotReady: Apps aren't loaded yet.

这是 wsgi.py 文件的样子:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

现在(使用 gunicorn 19.1.0 运行 Django 1.7):
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

更改最后两行修复了它。请注意,您的 DJANGO_SETTINGS_MODULE 可能不同,通常是“project_name.settings”

关于Django 1.7 升级错误 : AppRegistryNotReady: Models aren't loaded yet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25680803/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com