Categories
Python Answers

How to delete a record by id in Python Flask-SQLAlchemy?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *