title: Adding Foreign Key Fails in MySQL (errno 150)
body: <p>I've read many other posts about receiving MySQL errno 150 when trying to add a foreign key copnstraint, however I haven't found a solution yet. I hope I'm not doing something stupid. I made a simple test case.</p>
  <ol>
  <li><p>Both tables are InnoDB.</p>
  </li>
  <li><p>Both tables are UTF-8.</p>
  </li>
  <li><p><strike>Both columns are int(11) unsigned (making color_id <code>NOT NULL</code> doesn't make a difference).</strike> (<em>EDIT: I WAS WRONG ABOUT THIS, AND THIS WAS THE SOLUTION</em>)</p>
  <p>Here are my two tables:</p>
  </li>
  </ol>
  <p>Table <code>widgets</code>:</p>
  <pre><code>CREATE TABLE `widgets` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL DEFAULT '',
  `color_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>
  <p>Table <code>colors</code>:</p>
  <pre><code>CREATE TABLE `colors` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(10) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>
  <p>I just created these tables, there is no content. When I try to add a foreign key constraint to link widgets.color_id to colors.id, this happens:</p>
  <pre><code>mysql&gt; ALTER TABLE `widgets` ADD FOREIGN KEY (`color_id`) REFERENCES `color` (`id`);
  
  ERROR 1005 (HY000): Can't create table 'production.#sql-7b1_2dd7' (errno: 150)
  </code></pre>
  <p>I'll just add that I haven't been able to use my GUI tool of choice -- Sequel Pro on OSX -- either. I get the same error message when trying to create a foreign key relationship.</p>
  <p><code>SHOW ENGINE INNODB STATUS</code> returns this:</p>
  <pre><code>130531 17:23:06 Error in foreign key constraint of table production/#sql-7b1_2c80: 
  FOREIGN KEY (`color_id`) REFERENCES `colors` (`id`): Cannot find an index in 
  the referenced table where the referenced columns appear as the first columns, 
  or column types in the table and the referenced table do not match for constraint.
  </code></pre>
  <p>Am I doing something ridiculously stupid??</p>