[英]in sqlalchemy, how can I import existing table having foreign key on the other table
I have two Tables as bellow: 我有两个表如下:
table series
: 餐桌series
:
+-------------+
| Field |
+-------------+
| series_id |
| title |
+-------------+
table season
: 餐桌season
:
+-------------+
| Field |
+-------------+
| season_id |
| title |
| version |
| duration |
| series_id |
+-------------+
In season
, series_id
as foreign key referees from series(series_id)
在season
, series_id
作为来自series(series_id)
外籍裁判
Now I want load these two table via sqlalchemy. 现在,我想通过sqlalchemy加载这两个表。 Is that possible to build a one-to-many relationship between these two tables so that I can access all seasons object of one series? 是否可以在这两个表之间建立一对多关系,以便我可以访问一个系列的所有季节对象?
Yes you can! 是的你可以! The series_id
field of the season
table will be a foreign key to the series
table. season
表的series_id
字段将是series
表的外键。 To get all seasons of a particular series, you will query the 'season' table for all entries which have a particular series_id. 要获取特定系列的所有季节,您将在“季节”表中查询具有特定series_id的所有条目。
Look at this: http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#querying 看一下这个: http : //docs.sqlalchemy.org/en/latest/orm/tutorial.html#querying
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.