【问题标题】:Exception raised outside body: AppRegistryNotReady外部引发异常:AppRegistryNotReady
【发布时间】:2015-06-14 12:00:54
【问题描述】:

我在调用add_num.delay 时收到以下错误,从控制台看来,该方法已正确执行它,因为它输出 3(我将 1、2 作为 args 传递)。

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

我已经完成了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.

【问题讨论】:

    标签: python django celery django-celery


    【解决方案1】:

    看起来您已经使用 django

    尝试将您的 wsgi.py 文件更改为

    import os
    import sys
    
    from django.core.wsgi import get_wsgi_application
    
    application = get_wsgi_application()
    

    结帐https://docs.djangoproject.com/en/dev/releases/1.7/#wsgi-scripts

    【讨论】:

    猜你喜欢
    • 2013-04-19
    • 2011-07-16
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多