title: Cannot change primary key because of "incorrectly formed foreign key constraint" error
body: <p>I have a table which has the below schema definition :</p>
  
  <pre><code>CREATE TABLE `currency` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `code` char(3) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
    `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL
    PRIMARY KEY (`id`),
    UNIQUE KEY `code_UNIQUE` (`code`)
  ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>What I want is to drop the <code>id</code> column and make <code>code</code> as the new primary key. And some of the other tables are having foreign keys to this table. I tried the below command but failed:</p>
  
  <pre><code>SET FOREIGN_KEY_CHECKS=0;
  ALTER TABLE `currency` CHANGE COLUMN `id` `id` INT(11) NOT NULL, DROP PRIMARY KEY;
  ALTER TABLE currency ADD PRIMARY KEY (code);
  SET FOREIGN_KEY_CHECKS=1;
  </code></pre>
  
  <p>MySQL throws the  below exception:</p>
  
  <blockquote>
    <p>[ERROR in query 2] Error on rename of './db/#sql-849_1' to './db/currency' (errno: 150 - Foreign key constraint is incorrectly formed)
        Execution stopped!</p>
  </blockquote>