Modification of database by sqlalchemy

engine = create_engine ("mysql+pymysql://root:111@localhost/xxx", encoding="utf-8", echo=True)
Session_class = sessionmaker (bind=engine)
Session = Session_class ()

modify a record
user = Session.query (User). Filter_by (id=1). First ()
user.name = "aa_changed"

insert a record
user2 = User (name="bb", password="111")
Session.add (user2)

experiment 1:
neither submit nor query. I went to the database to check that there was no change

Lab 2:
does not submit, but I did a query operation. I didn"t expect to write it to the database!
Session.query (User). Filter (User.name.like ("zx*")). First ()
Session.query (User). Filter (User.name = =" zhl"). First ()
) this is it. I would like to ask: why can I modify the database with "only query but no submission"?

Mar.02,2021

Session.commit()

you lack this command.

in addition, learn sqlalchemy, to give you a benefit-- https://github.com/eastossifr.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b1632f-2aff2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b1632f-2aff2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?