[英]How can I add a foreign key constraint on an existing table column via SQLAlchemy?
[英]in sqlalchemy, how can I import existing table having foreign key on the other table
我有兩個表如下:
餐桌series
:
+-------------+
| Field |
+-------------+
| series_id |
| title |
+-------------+
餐桌season
:
+-------------+
| Field |
+-------------+
| season_id |
| title |
| version |
| duration |
| series_id |
+-------------+
在season
, series_id
作為來自series(series_id)
外籍裁判
現在,我想通過sqlalchemy加載這兩個表。 是否可以在這兩個表之間建立一對多關系,以便我可以訪問一個系列的所有季節對象?
是的你可以! season
表的series_id
字段將是series
表的外鍵。 要獲取特定系列的所有季節,您將在“季節”表中查詢具有特定series_id的所有條目。
看一下這個: http : //docs.sqlalchemy.org/en/latest/orm/tutorial.html#querying
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.