title: ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails
body: <p>When I execute the following SQL command:</p>
  
  <pre><code>INSERT INTO test_usershosts (RID,userid,hid,Usr,Pass) 
  VALUES (NULL,1,1,"user","pass");
  </code></pre>
  
  <p>I'm getting the following error message:</p>
  
  <pre><code>ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
  ails (`dm`.`test_usershosts`, CONSTRAINT `test_usershosts_ibfk_1` FOREIGN KEY (`
  userid`) REFERENCES `test_users` (`userid`) ON DELETE CASCADE ON UPDATE CASCADE)
  </code></pre>
  
  <p>My tables:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE IF NOT EXISTS `test_users` (
  `userid` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(10) NOT NULL DEFAULT '',
  `password` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (userid)
  ) ENGINE=InnoDB;
  
  INSERT INTO `test_users` (`userid`, `username`, `password) VALUES
  (1120, 'guest', '12250170a9624f336ca24');
  
  CREATE TABLE IF NOT EXISTS `test_hosts` (
  `hid` int(11) NOT NULL AUTO_INCREMENT,
  `UID` int(11) NOT NULL,
  `name` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (hid)
  ) ENGINE=InnoDB;
  
  INSERT INTO `test_hosts` (`hid`, `UID`, `name`) VALUES (30, 10, 'MU');
  
  CREATE TABLE IF NOT EXISTS `test_usershosts` (
  `RID` int(11) NULL AUTO_INCREMENT,
  `userid` int(11) ,
  `hid` int(11) ,
  `Usr` varchar(100) ,
  `Pass` varchar(100) ,
  PRIMARY KEY (RID),
  INDEX (userid),
  INDEX (hid),
  FOREIGN KEY (userid) REFERENCES test_users (userid) 
      ON DELETE CASCADE ON UPDATE CASCADE,
  FOREIGN KEY (hid) REFERENCES test_hosts (hid) 
      ON DELETE CASCADE ON UPDATE CASCADE
  ) ENGINE=InnoDB;
  </code></pre>
  
  <p>I've looked into many similar cases, but couldn't find any solution. Any help would be appreciated.</p>