title: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails
body: <p>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. </p>
  
  <p>This is the problem encountered when i run the code: </p>
  
  <blockquote>
    <p>SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or
    update a parent row: a foreign key constraint fails
    (<code>spwtd-test</code>.<code>training_user_answers</code>, CONSTRAINT
    <code>training_user_answers_training_user_id_foreign</code> FOREIGN KEY
    (<code>training_user_id</code>) REFERENCES <code>training_users</code> (<code>id</code>))</p>
  </blockquote>
  
  <p>this is the snippet code in <strong>loginController</strong>:</p>
  
  <pre><code>if ($completed = UserSyllabus::where('is_completed',1)-&gt;first())
         {$aa = UserAnswer::where('training_user_id')
          $userss = User::where('login_id', $request-&gt;login_id)
         -&gt;where( 'last_logout', '&lt;', Carbon::now()-&gt;subYears(2))
         -&gt;delete();}
  </code></pre>