title: Foreign key not working in MySQL: Why can I INSERT a value that's not in the foreign column?
body: <p>I've created a table in MySQL:</p>
  
  <pre><code>CREATE TABLE actions ( A_id int NOT NULL AUTO_INCREMENT,
  type ENUM('rate','report','submit','edit','delete') NOT NULL,
  Q_id int NOT NULL,
  U_id int NOT NULL,
  date DATE NOT NULL,
  time TIME NOT NULL,
  rate tinyint(1),
  PRIMARY KEY (A_id),
  CONSTRAINT fk_Question FOREIGN KEY (Q_id) REFERENCES questions(P_id),
  CONSTRAINT fk_User FOREIGN KEY (U_id) REFERENCES users(P_id));
  </code></pre>
  
  <p>This created the table I wanted just fine (although a "DESCRIBE actions;" command showed me that the foreign keys were keys of type MUL, and I'm not sure what this means).  However, when I try to enter a Q_id or a U_id that does not exist in the questions or users tables, <strong>MySQL still allows these values.</strong></p>
  
  <p>What did I do wrong?  How can I prevent a table with a foreign key from accepting invalid data?</p>
  
  <h2>UPDATE 1</h2>
  
  <p>If I add <code>TYPE=InnoDB</code> to the end, I get an error:</p>
  
  <blockquote>
    <p>ERROR 1005 (HY000): Can't create table './quotes/actions.frm' (errno: 150)</p>
  </blockquote>
  
  <p>Why might that happen?</p>
  
  <h2>UPDATE 2</h2>
  
  <p>I'm told that it's important to enforce data integrity with functional foreign keys, but also that InnoDB should not be used with MySQL.  What do you recommend?</p>