Soft Delete
- Soft delete is a widely used pattern in business application
- In Which case we need soft delete
- History tracking and audit
- Keeping referential integrity
- You need "Graceful delete"
- How to implement?
- Add a column called as
Is_Deleted
which represents a boolean value
- When you are querying for records select only the record where is_deleted = False
- In some case if you need to record when the record was deleted you can add an extra columen
Delete_Date
- Now lets try to implement this for our recipe Model Refer Here
- Now execute
flask db migrate -m "Added soft delete" # to create a migration revision
flask db upgrade

- Now submit/commit the changes to version control system Refer Here for the changes done
- The column is added to the database
- The problem with the current migration is our is_default is having null value for all the old records which is not acceptable, so lets try to fix that
- Refer Here for the changes
Like this:
Like Loading...