title: Why can't I add a foreign key constraint this way?
body: <p>Tables:    </p>
  
  <pre><code>    CREATE TABLE `relation` (
       `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
       `name` varchar(40) NOT NULL,
       `gender` tinyint(1) DEFAULT NULL,
       PRIMARY KEY (`id`),
       UNIQUE KEY `unique_relation` (`name`)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  
      CREATE TABLE `invite` (
       `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
       `date_sent` date NOT NULL,
       `user_id` int(10) unsigned NOT NULL,
       `relation_id` int(10) unsigned NOT NULL,
       `email` varchar(255) NOT NULL,
       `code` varchar(255) NOT NULL,
       PRIMARY KEY (`id`),
       KEY `fk_user` (`user_id`),
       CONSTRAINT `fk_user` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  </code></pre>
  
  <p>The SQL statement executed was:</p>
  
  <pre><code>ALTER TABLE `invite` 
  ADD CONSTRAINT `fk_relation`  
  FOREIGN KEY (`relation_id`) 
  REFERENCES `relation` (`id`) 
  ON DELETE CASCADE ON UPDATE RESTRICT
  </code></pre>
  
  <p>Mysql Error:</p>
  
  <p><strong><code>SQLSTATE[HY000]: General error: 1005 Can't create table 'dbtest.#sql-d00_39' (errno: 121).</code></strong></p>
  
  <p>The <strong>relation.id</strong> and <strong>invite.relation_id</strong> columns are of the same type int(10) unsigned</p>
  
  <p><strong>UPDATE</strong>
  The table invite is empty while adding this key.
  The table relation has 3 rows.</p>