I wanted to delete a user profile, when the last logout time was 2 years ago and there is no current activities were made during that time.
This is the problem encountered when i run the code:
SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (
spwtd-test
.training_user_answers
, CONSTRAINTtraining_user_answers_training_user_id_foreign
FOREIGN KEY (training_user_id
) REFERENCEStraining_users
(id
))
this is the snippet code in loginController:
if ($completed = UserSyllabus::where('is_completed',1)->first())
{$aa = UserAnswer::where('training_user_id')
$userss = User::where('login_id', $request->login_id)
->where( 'last_logout', '<', Carbon::now()->subYears(2))
->delete();}