基于另一个选项卡中的值的简单SQLAlchemy更新表

2024-04-26 23:31:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个新来的SQLAlchemy,所以请原谅这是一个基本的问题。在

我有一个数据库表properties(在SQLALchemy中映射为对象Property),其中包含一个字段MEBID。我有另一个表mebs(在SQLAlchemy中映射为MEB)。我想设置属性.MEBID字段到mebs.id哪里属性.邮政编码== mebs.邮政编码. 在

我可以在SQL中使用命令

update properties, mebs set properties.mebid = mebs.id where mebs.PostCode = properties.PostCode

但我在苦于用SQLAlchemy做这件事。如果我尝试命令

^{pr2}$

我明白了

InvalidRequestError: This operation requires only one Table or entity be specified as the target.

我知道这必须是基本的,因为这是一个基本的操作,但不知道是怎么做到的。在


Tags: 对象命令id数据库sql属性sqlalchemyproperty