如何使用对象在 sqlalchemy 中更新?

How to Update in sqlalchemy using objects?

我有一个学生 table 在 postgres 中使用以下列 学生编号 | Student_name | Student_division

我正在使用 sql 炼金术并将其建模为

     Class Student:
     _tablename__ : 'student'
     __table_args__ : {'schema' : 'student'}

     studentid=Column('Student_name', pk=true)
.
. And so on for rest of the columns.

#After creating object of the same
    stu = Student()

#I want the values be updated by user.
#The statement i have written is as
    x= session.query(Student).get(id) #id #given by user
    x.studentid= studentid #given by uset #models
    x.studentname = name
    session.add(x)
    session.commit()

如何更新?这行不通。

您需要提交更改并删除 session.add(x)

保持session.commit()