Update a Joined Table with SQLAlchemy Core

后端 未结 1 1815
野性不改
野性不改 2021-01-14 01:45

I have a MySQL db with tables set up like this:

Table1      Table2
------      ------
  id          id, fk to Table1.id
  name        name

1条回答
  •  时光说笑
    2021-01-14 02:38

    upd = table1.update()\
        .values(id=table2.c.id)\
        .where(table1.c.name == table2.c.name)
    

    should do it, but if you really have all those foreign keys, you might get errors doing such updates.

    0 讨论(0)
提交回复
热议问题