I'm using SQLAlchemy with python and i want to update specific row in a table which equal this query:
UPDATE User SET name = 'user' WHERE id = '3'
I made this code by sql alchemy but it's not working:
session.query(User).filter(User.id==3).update({'name': 'user'})
returned this error:
InvalidRequestError: Could not evaluate current criteria in Python. Specify 'fetch' or False for the synchronize_session parameter.
How can i do it?
ormically, you don't use update()
, you set attributes:
a_user = session.query(User).filter(User.id == 3).one()
a_user.name = "user"
session.commit()
session.query(User).filter(User.id==3).update({'name':'user'},synchronize_session=False)
This would work. Read about syncrhonize_session in sqlalchemy documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With