In SQL Alchemy you are deleting Objects that you get with a query from the database. This you can do in 2 Ways:

Deleting with query (will issue just one DELETE statement):

session.query(User).filter(User.id==7).delete()
session.commit()
Deleting object instance returned by a query (will issue 2 statements: first SELECT, then DELETE):

obj=session.query(User).filter(User.id==7).first()
session.delete(obj)
session.commit()

 

from: https://stackoverflow.com/a/26643978/8025086

posted on 2019-05-31 18:56  Go_Forward  阅读(231)  评论(0编辑  收藏  举报