简体   繁体   English

web2py数据库中的外键

[英]Foreign keys in web2py database

I use web2py framework with two tables. 我使用带有两个表的web2py框架。 How can I refer one field from first table into second table? 如何将第一个表中的一个字段引用到第二个表中?

Here's the section on table relationships and JOINs from the web2py chapter on databases 以下是关于数据库web2py章节中关于表关系和JOIN的部分

To illustrate how to implement one to many relations with the web2py DAL, define another table "dog" that refers to the table "person" which we redefine here: 为了说明如何使用web2py DAL实现一对多关系,请定义另一个表“dog”,它引用我们在此处重新定义的表“person”:

>>> db.define_table('person',
                    Field('name'),
                    format='%(name)s')
>>> db.define_table('dog',
                    Field('name'),
                    Field('owner', db.person),
                    format='%(name)s')

You'll need to provide more information if you are looking for something that's not covered in that reference. 如果您正在寻找该参考文献中未涵盖的内容,则需要提供更多信息。

See The Database Abstraction Layer chapter of the book, in particular, the section on One to Many Relations . 请参阅本书的“数据库抽象层”一章,特别是“ 一对多关系”一节。 If you're working with a pre-existing/legacy database, see Legacy Databases and Keyed Tables . 如果您正在使用预先存在的/旧数据库,请参阅旧数据库和键控表 Also, here's an example . 另外,这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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