[英]Foreign Keys in web2py
I keep getting this error: 'DAL' object has no attribute 'event_instance'
我不断收到此错误: “ DAL”对象没有属性“ event_instance”
it points to my db_agents file as the culprit on this line: 它指向这行的罪魁祸首是我的db_agents文件:
('event_instance_id', db.event_instance)
However if I move the definition of the event_instance table to that db_agents model file the error disappears, but I get a new one referering to another FKey in the event_instance tbl. 但是,如果我将event_instance表的定义移到该db_agents模型文件中,该错误消失了,但是我在event_instance tbl中得到了一个引用另一个FKey的新引用。 Is there a way to avoid having all my db.define_tables in the same file, I would like to keep them separate.
有没有一种方法可以避免将所有db.define_tables放在同一文件中,我想将它们分开。
You can do: 你可以做:
Field('event_instance_id', 'reference event_instance')
Using that alternative syntax, it is not necessary for the "event_instance" table to be defined already. 使用该替代语法,不必已经定义“ event_instance”表。
Also, note that model files are executed in alphabetical order, so your original code will work as long as the "event_instance" table is defined in a model file that comes earlier in alphabetical order. 另外,请注意,模型文件是按字母顺序执行的,因此只要在按字母顺序排在前面的模型文件中定义了“ event_instance”表,您的原始代码就可以使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.