Sometimes, we want to delete a record by id in Python Flask-SQLAlchemy.
In this article, we’ll look at how to delete a record by id in Python Flask-SQLAlchemy.
How to delete a record by id in Python Flask-SQLAlchemy?
To delete a record by id in Python Flask-SQLAlchemy, we can call the session delete method.
For instance, we write
session.delete(obj1)
session.delete(obj2)
session.commit()
to call session.delete to mark obj1 and obj2 to be deleted.
And then we call session.commit to commit the delete operations.
Conclusion
To delete a record by id in Python Flask-SQLAlchemy, we can call the session delete method.