Modify the foreign key constraint in database

Cascade Deletion: You can set up the foreign key constraint to allow cascading deletes. This means that when a user is deleted from the users table, all related rows in the grades table will also be deleted automatically.

ALTER TABLE grades
DROP FOREIGN KEY grades_ibfk_1;

ALTER TABLE grades
ADD CONSTRAINT grades_ibfk_1
FOREIGN KEY (user_id) REFERENCES users(id)
ON DELETE CASCADE;