0

我正在尝试使用安东尼发布的方法

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”

知道为什么吗?

4

1 回答 1

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')
于 2013-07-24T21:46:40.040 回答