Sqlalchemy used to insert data in the flask returned id added

user = User ( 'name' = ' John Doe')
db.session.add (User)
db.session.flush ()
# outputs a new primary key data inserted
Print (the user.id)
# At this time the data was inserted into the database
db.session.commit ()

 

Guess you like

Origin www.cnblogs.com/shengs/p/12074942.html