title: Cannot add or update a child row: foreign key constraint fails
body: <p>Hi I am wondering why I getting an error </p>
  
  <blockquote>
    <p>ERROR 1452 (23000): Cannot add or update a child row: a foreign key
    constraint fails (<code>exams</code>.<code>entries</code>, CONSTRAINT <code>entries_ibfk_2</code>
    FOREIGN KEY (<code>student_id</code>) REFERENCES <code>students</code> (<code>student_id</code>))</p>
  </blockquote>
  
  <p>Any help would be appriatiated! </p>
  
  <p>Here are the scripts that I think are relevant to the problem I'm having,</p>
  
  <p>First I made this table entries and everything was fine</p>
  
  <pre><code>CREATE TABLE entries(
  subject_id INT UNSIGNED NOT NULL,
  subject_name VARCHAR(60) NOT NULL,
  level_of_entry VARCHAR(60) NOT NULL,
  exam_board VARCHAR(60) NOT NULL,
  student_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  date_of_exam DATETIME NOT NULL,
  PRIMARY KEY (date_of_exam),
  FOREIGN KEY (subject_id)
  REFERENCES subjects(subject_id),
  FOREIGN KEY (student_id)
  REFERENCES students(student_id)
  </code></pre>
  
  <p>Then I tried to insert data and I got the error.</p>
  
  <pre><code>INSERT INTO entries (subject_id,subject_name, level_of_entry, exam_board,date_of_exam)
  VALUE ('1','chemistry','as','ocr','2017-05-05 12:00:00'),
  ('2','biology','gcse','aqa','2017-05-05 12:00:01'),
  ('3','music','gcse','edexcel','2017-05-05 12:00:02'),
  ('4','english','a','ocr','2017-05-05 12:00:03'),
  ('5','physics','a','aqa','2017-05-05 12:00:04'),
  ('6','maths','gcse','aqa','2017-05-05 12:00:05'),
  ('7','computing','gcse','aqa','2017-05-05 12:00:06'),
  ('8','physical_education','gcse','aqa','2017-05-05 12:00:07'),
  ('9','design_and_technology','gcse','aqa','2017-05-05 12:00:08'),
  ('10','french','gcse','aqa','2017-05-05 12:00:09');
  </code></pre>
  
  <p>It suggest on other questions similar to this to make sure your parent table has the same values but it does and its making know sense to me.
  Here is the parent script.</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS students(
  student_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  first_name VARCHAR(20) NOT NULL,
  middle_name VARCHAR(20) NOT NULL,
  last_name VARCHAR(40) NOT NULL,
  email VARCHAR(60) NOT NULL,
  password CHAR(40) NOT NULL,
  reg_date DATETIME NOT NULL,
  PRIMARY KEY (student_id) ,
  UNIQUE (email));
  </code></pre>
  
  <p>Here is the other parent script but I'm having no problems with it.</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS subjects(
  subject_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  subject_name VARCHAR(60) NOT NULL,
  level_of_entry VARCHAR(60) NOT NULL,
  exam_board VARCHAR(60) NOT NULL,
  PRIMARY KEY (subject_id) ,
  UNIQUE (subject_id));
  </code></pre>
  
  <p>If anyone could help I would be extremely grateful! </p>