当我尝试在web2py中为scheduller创建一个新模型时,我收到一个错误。该模型如下
`def f():
a = 2
return ()
from gluon.scheduler import Scheduler
scheduler = Scheduler(db,dict(our_function=f))
我收到以下错误:
`
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 227, in restricted
exec ccode in environment
File "/home/www-data/web2py/applications/Home_Lights/models/mtasks.py", line `42, in <module>`
Scheduler(db,dict(our_function=f))
File "/home/www-data/web2py/gluon/scheduler.py", line 587, in __init__
self.define_tables(db, migrate=migrate)
File "/home/www-data/web2py/gluon/scheduler.py", line 655, in define_tables
format='%(task_name)s')
File "/home/www-data/web2py/gluon/packages/dal/pydal/base.py", line 799, in `define_table`
raise SyntaxError('table already defined: %s' % tablename)
SyntaxError: table already defined: scheduler_task`
我怀疑它与新创建的模型的执行权限有关。任何帮助表示赞赏......?
答案 0 :(得分:1)
刚设置:
migrate=False
因此它不会尝试重新创建表格
from gluon.scheduler import Scheduler
scheduler = Scheduler(db,tasks=dict(our_function=f), migrate=False)