title: MySql Insert Foreign key Constraint Fails
body: <p>I have two tables, Students and Courses. A Student can en-roll in multiple courses. Here is the EER diagram I have for the tables</p>
  
  <p><a href="https://i.stack.imgur.com/Czztk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Czztk.png" alt="enter image description here"></a></p>
  
  <p>I have records both in Student and Course table with Ids 1. When I enter into student_courses table those two Ids , i am getting back foreign_key constraint failed error.</p>
  
  <pre><code>FOREIGN KEY (`student_courses_sno`) REFERENCES `courses` (`sno`) ON DELETE NO ACTION ON UPDATE )
  </code></pre>
  
  <p><strong>Error Message</strong></p>
  
  <blockquote>
    <p>ERROR 1452: 1452: Cannot add or update a child row: a foreign key
    constraint fails (<code>pp_production</code>.<code>student_courses</code>, CONSTRAINT
    <code>fk_student_courses_courses1</code> FOREIGN KEY (<code>courses_sno</code>) REFERENCES
    <code>courses</code> (<code>sno</code>) ON DELETE NO ACTION ON UPDATE ) SQL Statement:
    INSERT INTO <code>pp_production</code>.<code>student_courses</code> (<code>sno</code>, <code>courses_sno</code>,
    <code>students_sno</code>) VALUES ('1', '227', '1')</p>
  </blockquote>
  
  <p>What am I doing wrong here?</p>