我有一个在flask上运行的应用程序,该应用程序使用sqlalchemy与数据库进行交互.我想用用户指定的值更新表的列.我正在使用的查询是
I have an app that runs on flask and uses sqlalchemy to interact with the data base. I want to update the columns of a table with the user specified values. The query that I am using is
def update_table(value1, value2, value3): query = update(Table).where(Table.column1 == value1).values(Table.column2 = value2, Table.column3 = value3)我不确定我传递值的方式是否正确.还有Table.column2/3 i =给出错误,说Can't assign to function call.如果column2/3不是函数,则为字段名称.那么,我该如何更新多个值,为什么在这里会给出错误呢?
I am not sure if the way I am passing values is correct. Also the Table.column2/3 i=gives error saying Can't assign to function call . Where column2/3 are not functions, they're field names. So, how do I update multiple values and why is it giving error here?
PS:我提到了sqlalchemy doc
PS: I referred the sqlalchemy doc
推荐答案可以使用会话"将多个列更新为:
Multiple columns can be updated using the Session as:
def update_table(session, val1, val2, val3): session.query(Table).filter_by(col=val1).update(dict(col2=val2,col3=val3)) sessionmit()更多推荐
在Sqlalchemy中更新多列
发布评论