title: Why won't my foreign key create in MySQL?
body: <p>I've tried many different ways to create table with a foreign key and trying to insert into phpMyAdmin. However, it just not working as I was expected.</p>
  
  <p>Here are what I've so far:</p>
  
  <pre><code>CREATE TABLE user (
      user_id BIGINT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
      user_name VARCHAR(50) NOT NULL,
      user_password VARCHAR(50) NOT NULL);
  </code></pre>
  
  <p>This works perfectly fine. However, if I try to add a table with a foreign key thus, it refuses to create:</p>
  
  <pre><code>CREATE TABLE article (
      article_id INT(20) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
      article_title VARCHAR(100) NOT NULL,
      article_content VARCHAR(1000) NOT NULL,
      user_id INT(10) NOT NULL,
      FOREIGN KEY (user_id) REFERENCES user (user_id));
  </code></pre>
  
  <p>This would not work as expected and would not add the table to the MySQL database. I get this error:</p>
  
  <blockquote>
    <p>Cannot add foreign key constraint</p>
  </blockquote>
  
  <p>How can I fix it?</p>