自定义django管理命令:使用模型和crontab存在问题
我创建了自定义的django管理命令。我使用这个教程 例如,我的命令:自定义django管理命令:使用模型和crontab存在问题,django,Django,我创建了自定义的django管理命令。我使用这个教程 例如,我的命令: import os from home.models import BuildTask class Command(BaseCommand): def handle(self, *args, **options): tasks = BuildTask.objects.all() os.system("touch /Users/macbook/Desktop/Start.txt")
import os
from home.models import BuildTask
class Command(BaseCommand):
def handle(self, *args, **options):
tasks = BuildTask.objects.all()
os.system("touch /Users/macbook/Desktop/Start.txt")
if tasks:
os.system("touch /Users/macbook/Desktop/TasksExist.txt")
else:
os.system("touch /Users/macbook/Desktop/TasksNotExist.txt")
os.system("touch /Users/macbook/Desktop/End.txt")
使用终端运行此命令时:
python manage.py build_task
一切正常,我在Destop上有3个文件
但是当我使用crontab时
* * * * * /usr/bin/python /Users/macbook/builder/manage.py build_task
我只是在桌面上得到一个文件(“Start.txt”)。很明显,脚本在线路上停止了作业
if tasks:
请帮帮我。有什么问题吗
更新:/var/mail/macbook:
File "/Users/macbook/workspace/acodebuilder/home/management/commands/build_apk.py",
line 26, in handle
if tasks:
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 113, in
__nonzero__
iter(self).next()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 107, in
_result_iter
self._fill_cache()
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 772, in
_fill_cache
self._result_cache.append(self._iter.next())
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 273, in
iterator
for row in compiler.results_iter():
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 680, in
results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 735, in
execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 34, in
execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py", line 234,
in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: home_buildtask
为什么“没有这样的表”通过运行
mail
命令,您应该能够看到命令的错误输出(如果有)。或者,您可以将&>~/Desktop/django command error.log
附加到crontab条目,cron作业的错误输出将保存到桌面上的django command error.log
。这是由SQLite db引起的问题,我们必须使用MySQL或PGSQL