Delete and Handle Missing Rows
Remove records and 404 when absent.
The D in CRUD
Deleting removes a row for good. Like updating, you first load the record, then tell the session to drop it. 🗑️
Load the Target Row
Fetch the record by id before deleting. With get_or_404() a missing id stops the request cleanly with a 404.
user = User.query.get_or_404(user_id)All lessons in this course
- Create Records and Commit Sessions
- Read One and Read Many Endpoints
- Update Existing Records Safely
- Delete and Handle Missing Rows