Python 在主体外部引发的异常:AppRegistryNotReady

Python 在主体外部引发的异常:AppRegistryNotReady,python,django,celery,django-celery,Python,Django,Celery,Django Celery,调用add_num.delay时出现以下错误,从控制台上看,该方法在输出3(我将1、2作为参数传递)后已正确执行 我不明白为什么会发生这种错误。请帮我解决这个问题 我已经完成了syncdb [2015-04-09 13:25:43,378: INFO/MainProcess] Received task: brokermanager.tasks.a dd_num[a4d84bb5-e22f-466e-918f-0bcc5b449529] [2015-04-09 13:25:43,380: WAR

调用
add_num.delay
时出现以下错误,从控制台上看,该方法在输出3(我将1、2作为参数传递)后已正确执行

我不明白为什么会发生这种错误。请帮我解决这个问题

我已经完成了syncdb

[2015-04-09 13:25:43,378: INFO/MainProcess] Received task: brokermanager.tasks.a
dd_num[a4d84bb5-e22f-466e-918f-0bcc5b449529]
[2015-04-09 13:25:43,380: WARNING/Worker-1] add_num
[2015-04-09 13:25:43,381: WARNING/Worker-1] 3
[2015-04-09 13:25:43,390: WARNING/Worker-1] C:\Python27\lib\site-packages\celery
\app\trace.py:365: RuntimeWarning: Exception raised outside body: AppRegistryNotReady("Models aren't loaded yet.",):
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\celery\app\trace.py", line 283, in trace_task
    uuid, retval, SUCCESS, request=task_request,
  File "C:\Python27\lib\site-packages\celery\backends\base.py", line 256, in store_result
    request=request, **kwargs)
  File "C:\Python27\lib\site-packages\djcelery\backends\database.py", line 29, in _store_result
    traceback=traceback, children=self.current_task_children(request),
  File "C:\Python27\lib\site-packages\djcelery\managers.py", line 42, in _inner return fun(*args, **kwargs)
  File "C:\Python27\lib\site-packages\djcelery\managers.py", line 181, in store_result    'meta': {'children': children}})
  File "C:\Python27\lib\site-packages\djcelery\managers.py", line 87, in update_or_create
    return get_queryset(self).update_or_create(**kwargs)
  File "C:\Python27\lib\site-packages\djcelery\managers.py", line 70, in update_or_create
    obj, created = self.get_or_create(**kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 422, in get_or_create
    return self.get(**lookup), False
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 345, in get
    clone = self.filter(*args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 691, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "C:\Python27\lib\site-packages\django\db\models\query.py", line 709, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "C:\Python27\lib\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 "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1314, in _add_q
    current_negated=current_negated, connector=connector)
  File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1138, in build_filter
    lookups, parts, reffed_aggregate = self.solve_lookup_type(arg)
  File "C:\Python27\lib\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 "C:\Python27\lib\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 "C:\Python27\lib\site-packages\django\db\models\options.py", line 416, in
 get_field_by_name
    cache = self.init_name_map()
  File "C:\Python27\lib\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 "C:\Python27\lib\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 "C:\Python27\lib\site-packages\django\db\models\options.py", line 577, in
 _fill_related_many_to_many_cache
    for klass in self.apps.get_models():
  File "C:\Python27\lib\site-packages\django\utils\lru_cache.py", line 101, in w
rapper
    result = user_function(*args, **kwds)
  File "C:\Python27\lib\site-packages\django\apps\registry.py", line 168, in get
_models
    self.check_models_ready()
  File "C:\Python27\lib\site-packages\django\apps\registry.py", line 131, in che
ck_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
AppRegistryNotReady: Models aren't loaded yet.

看起来您已经使用django<1.7创建了项目,现在升级到django==1.7

尝试将wsgi.py文件更改为

import os
import sys

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

结帐

Nope,添加导入django后再次发生相同问题;django.setup()