Flask-SQLalchemy 更新一行的信息 [英] Flask-SQLalchemy update a row's information
本文介绍了Flask-SQLalchemy 更新一行的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更新一行的信息?
例如,我想更改 id 为 5 的行的名称列.
For example I'd like to alter the name column of the row that has the id 5.
推荐答案
使用 Flask-SQLAlchemy 文档中显示的教程.拥有要更改的实体后,请更改实体本身.然后,db.session.commit()
.
Retrieve an object using the tutorial shown in the Flask-SQLAlchemy documentation. Once you have the entity that you want to change, change the entity itself. Then, db.session.commit()
.
例如:
admin = User.query.filter_by(username='admin').first()
admin.email = 'my_new_email@example.com'
db.session.commit()
user = User.query.get(5)
user.name = 'New Name'
db.session.commit()
Flask-SQLAlchemy 基于 SQLAlchemy,所以一定要查看 SQLAlchemy Docs.
Flask-SQLAlchemy is based on SQLAlchemy, so be sure to check out the SQLAlchemy Docs as well.
这篇关于Flask-SQLalchemy 更新一行的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文