我正在尝试使用Anthony
发布的方法db.define_table('ts_customer',
Field('customer_name', 'string', length=80, required=True, unique=True))
db.define_table('ts_mileage_rate',
Field('customer_id', 'reference ts_customer', required=True, notnull=True),
Field('mileage_rate_year', 'integer', required=True, notnull=True,
requires=IS_NOT_IN_DB(
db(db.ts_mileage_rate.customer_id == request.vars.customer_id),
'ts_mileage_rate.mileage_rate_year')
))
我收到以下错误:
输入'exceptions.AttributeError'> 'DAL'对象没有属性'ts_mileage_rate'
知道为什么吗?
答案 0 :(得分:0)
db.ts_mileage_rate.customer_id
表的定义中有ts_mileage_rate
,因此该表尚不存在。而是在表定义之后定义requires
属性:
db.ts_mileage_rate.mileage_rate_year.requires = IS_NOT_IN_DB(
db(db.ts_mileage_rate.customer_id == request.vars.customer_id),
'ts_mileage_rate.mileage_rate_year')