简体   繁体   中英

Foreign Keys in web2py

I keep getting this error:

it points to my db_agents file as the culprit on this line:

('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. Is there a way to avoid having all my db.define_tables in the same file, I would like to keep them separate.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM