Dipnesh Dipnesh - 5 months ago 27
SQL Question

how to update data of one column for all row in SqlAlchemy?

for single record update i have tried below code and its working

uid=1

info = Info.query.filter_by(id=uid).first()
info.sold_status ='1'
db.session.add(info)
db.session.commit()


now i want to update one column multiple row
i have tried

for row in db.session.query(Uninstall.status).all():
print row.status

abc=row.status
abc=uid

db.session.add(row.status)
db.session.commit()


but it's not working.

thanks in advance :)

Answer
for row in Uninstall.query.all():
    print row.status
    row.status = <new status>
    db.session.add(row)
    db.session.commit()