SQL Alchemy - How to Delete from a model instance?
Say I get a model instance like this:
instance = session.query(MyModel).filter_by(id=1).first()
How can I delete that开发者_C百科 row? Is there a special method to call?
Ok I found it after further searching:
session.delete(instance)
You can fire a Single query for this.
For all records
session.query(MyModel).delete()
session.commit()
It will delete all records from it and if you want to delete specific records then try filter clause in the query. ex.
For specific value
session.query(MyModel).filter(MyModel.id==1).delete()
session.commit()
精彩评论