djcelery 异常报错解决方案

1. TypeError: can only concatenate tuple (not “NoneType”) to tuple

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "D:\Python27\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "D:\Python27\lib\site-packages\django\core\management\__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\Python27\lib\site-packages\django\core\management\__init__.py", line 190, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "D:\Python27\lib\site-packages\django\core\management\__init__.py", line 40, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "D:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
  File "D:\Python27\lib\site-packages\djcelery\management\commands\celery.py", line 11, in <module>
    class Command(CeleryCommand):
  File "D:\Python27\lib\site-packages\djcelery\management\commands\celery.py", line 15, in Command
    base.get_options() +
TypeError: can only concatenate tuple (not "NoneType") to tuple

这个问题是由于安装包不全导致的,分别检查是否安装了以下安装包:

pip install celery

pip install celery-with-redis

pip install django-celery


2. AppRegistryNotReady: Models aren’t loaded yet.

Traceback (most recent call last):
  File "D:\Python27\lib\site-packages\celery\app\trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "D:\Python27\lib\site-packages\celery\app\trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "F:\virtual\project\agrometeorological\agrometeorological\ganter\tasks.py", line 34, in get_access
    g.account_set.all()
  File "D:\Python27\lib\site-packages\django\db\models\manager.py", line 228, in all
    return self.get_queryset()
  File "D:\Python27\lib\site-packages\django\db\models\fields\related.py", line 712, in get_queryset
    qs = qs.filter(**self.core_filters)
  File "D:\Python27\lib\site-packages\django\db\models\query.py", line 679, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "D:\Python27\lib\site-packages\django\db\models\query.py", line 697, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "D:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1310, in add_q
    clause, require_inner = self._add_q(where_part, self.used_aliases)
  File "D:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1338, in _add_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "D:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1150, in build_filter
    lookups, parts, reffed_expression = self.solve_lookup_type(arg)
  File "D:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1036, in solve_lookup_type
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
  File "D:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1373, in names_to_path
    if field.is_relation and not field.related_model:
  File "D:\Python27\lib\site-packages\django\utils\functional.py", line 59, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Python27\lib\site-packages\django\db\models\fields\related.py", line 110, in related_model
    apps.check_models_ready()
  File "D:\Python27\lib\site-packages\django\apps\registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
AppRegistryNotReady: Models aren't loaded yet.

我是在定时任务中使用外键关联的反向查询时报了上面的错误:

模型加载不全,解决方式是在定时任务tasks文件的包引用最前面引用,如下:

# -*- coding:utf-8 -*-

import django
django.setup()
from celery.schedules import crontab_parser
from celery import shared_task
发布了57 篇原创文章 · 获赞 232 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/qq_23934063/article/details/82633235