最终,我想让 Django 1.9 的测试通过。 django-celery 目前适用于 Django 我在一个测试项目中克隆了 https://github.com/celery/django-celery 并安装了需求。对于 Django 1.7,测试正在通过。对于 Django 1.8,我多次遇到相同的错误,但它应该可以工作...参见 https://github.com/celery/django-celery/blob/master/tox.ini 包含 Django 1.8:...1.8: Django>=1.8.0,<1.9.0对于 Django 1.7:pip install Django==1.7./django-celery/tests/manage.py test djcelery.tests...Ran 64 tests in 0.319sOK对于 Django 1.8:pip install Django==1.8./django-celery/tests/manage.py test djcelery.tests...======================================================================ERROR: test_all_as_schedule (djcelery.tests.test_schedulers.test_DatabaseScheduler)----------------------------------------------------------------------Traceback (most recent call last): File "/Users/francois/web/test_project/django-celery/djcelery/tests/test_schedulers.py", line 110, in setUp m1 = create_model_interval(schedule(timedelta(seconds=10))) File "/Users/francois/web/test_project/django-celery/djcelery/tests/test_schedulers.py", line 20, in create_model_interval **kwargs) File "/Users/francois/web/test_project/django-celery/djcelery/tests/test_schedulers.py", line 40, in create_model return Model(**dict(entry, **kwargs)) File "/Users/francois/Envs/test_project/lib/python2.7/site-packages/django/db/models/base.py", line 468, in __init__ setattr(self, field.name, rel_obj) File "/Users/francois/Envs/test_project/lib/python2.7/site-packages/django/db/models/fields/related.py", line 668, in __set__ (value, self.field.rel.to._meta.object_name)ValueError: Cannot assign "<IntervalSchedule: every 10.0 seconds>": "IntervalSchedule" instance isn't saved in the database. ... Ran 64 tests in 0.150s FAILED (errors=15)我错过了什么? 最佳答案 Django 1.8 有一个 API 更改,可防止将未保存的模型实例添加为外键:https://docs.djangoproject.com/en/1.8/releases/1.8/#assigning-unsaved-objects-to-relations-raises-an-error关于testing - 在 Django 1.8 上运行 django-celery 测试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33604025/