I am trying to delete a single row from tbl_user and multiple rows from user_subscription_log, my join query is:
DELETE tbl_user, user_subscription_log
INNER JOIN user_subscription_log ON tbl_user.id = user_subscription_log.user_id
It's failing because a child record exists in
user_subscription_log table and, no 'on delete' clause is set in Foreign key.
I'd execute two delete queries:
DELETE FROM user_subscription_log WHERE user_id = ?; DELETE FROM tbl_user where id = ?;
Another option is to set 'on delete cascade' clause in the foreign key definition, as explained here.