2
我添加了一個新表,我的web2py應用程序:新表無法識別
db.define_table('users',
db.Field('name', 'string'),
db.Field('password', 'password'),
db.Field('reputation', 'integer', default=0),
db.Field('joined', 'datetime', default=datetime.utcnow())
)
而且一箇舊表中的字段引用它:
db.Field('user', db.users),
但是,這是給我一個KeyError
以下回溯:
Traceback (most recent call last):
File "E:\Programming\Python\web2py\gluon\restricted.py", line 204, in restricted
exec ccode in environment
File "E:/Programming/Python/web2py/applications/vote_up/models/db.py", line 85, in <module>
db.Field('user', db.users),
File "E:\Programming\Python\web2py\gluon\dal.py", line 5119, in __getattr__
return self[key]
File "E:\Programming\Python\web2py\gluon\dal.py", line 5113, in __getitem__
return dict.__getitem__(self, str(key))
KeyError: 'users'
我該如何解決這個問題?
:D我有多愚蠢。我並沒有將'define_table'看作python方法,而是將其視爲一種神祕的Web2Py結構,就像我在PHP日期間用來查看MySQL查詢:D。再次感謝@安東尼。 – Sathvik 2012-02-26 14:29:12