I have a student table in postgres with the following columns Studentid | Student_name | Student_division
I am using sql alchemy and have modeled it as
JavaScript
x
19
19
1
Class Student:
2
_tablename__ : 'student'
3
__table_args__ : {'schema' : 'student'}
4
5
studentid=Column('Student_name', pk=true)
6
.
7
. And so on for rest of the columns.
8
9
#After creating object of the same
10
stu = Student()
11
12
#I want the values be updated by user.
13
#The statement i have written is as
14
x= session.query(Student).get(id) #id #given by user
15
x.studentid= studentid #given by uset #models
16
x.studentname = name
17
session.add(x)
18
session.commit()
19
How to update? This doesnt work.
Advertisement
Answer
you need to commit the changes and remove the session.add(x)
just keep session.commit()