title: ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails MySQL
body: <p>I've looked everywhere for a possible solution and haven't been able to find anything.</p>
  
  <p>Here are my tables:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS students(
  student_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  first_name VARCHAR(40) NOT NULL,
  middle_name VARCHAR(20),
  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>And, </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS subjects(
  subject_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  subject_name VARCHAR(20) NOT NULL,
  level_of_entry VARCHAR(12) NOT NULL,
  exam_board VARCHAR(12) NOT NULL,
  PRIMARY KEY (subject_id),
  UNIQUE(subject_id));
  </code></pre>
  
  <p>Finally, </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS entries (
  entry_id INT NOT NULL AUTO_INCREMENT,
  PRIMARY KEY(entry_id),
  student_id INT UNSIGNED NOT NULL,
  subject_id INT UNSIGNED NOT NULL,
  date_of_exam DATETIME NOT NULL,
  FOREIGN KEY (student_id) REFERENCES students (student_id),
  FOREIGN KEY (subject_id) REFERENCES subjects (subject_id));
  </code></pre>
  
  <p>I need to enter 5 records into the table entries using foreign keys from the other two tables. This is the code I used to enter records into entries:</p>
  
  <pre><code>INSERT INTO entries 
  VALUES (NULL,   NULL,   NULL,   '2010-04-19'),
  (NULL,  NULL,   NULL,   '2015-06-17'),
  (NULL,  NULL,   NULL,   '2011-07-21'),
  (NULL,  NULL,   NULL,   '2009-01-12'),
  (NULL,  NULL,   NULL,   '2016-11-16');
  </code></pre>
  
  <p>This error message is returned:</p>
  
  <pre><code>ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`exams`.`entries`, CONSTRAINT `entries_ibfk_1` FOREIGN KEY (`student_id`) REFERENCES `students` (`student_id`)) 
  </code></pre>
  
  <p>Any ideas or suggestions would be appreciated.</p>