In SQL Alchemy, you delete the objects that you receive with the query from the database. There are two ways to do this:
Deletion using a query (it produces only one statement DELETE):
session.query(User).filter(User.id==7).delete()
session.commit()
Removing an instance of the object returned by the request (gives 2 statements: first SELECT, then DELETE):
obj=session.query(User).filter(User.id==7).first()
session.delete(obj)
session.commit()
source
share