Skip to content Skip to sidebar Skip to footer

Updating Specific Row In Sqlalchemy

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

Solution 1:

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()

Solution 2:

session.query(User).filter(User.id==3).update({'name':'user'},synchronize_session=False)

This would work. Read about syncrhonize_session in sqlalchemy documentation.


Post a Comment for "Updating Specific Row In Sqlalchemy"