title: MySQL 1062 - Duplicate entry '0' for key 'PRIMARY'
body: <p>I have the following table in MySQL version 5.5.24</p>
  
  <pre><code>DROP TABLE IF EXISTS `momento_distribution`;
  
  CREATE TABLE IF NOT EXISTS `momento_distribution`
    (
       `momento_id`       INT(11) NOT NULL,
       `momento_idmember` INT(11) NOT NULL,
       `created_at`       DATETIME DEFAULT NULL,
       `updated_at`       DATETIME DEFAULT NULL,
       `unread`           TINYINT(1) DEFAULT '1',
       `accepted`         VARCHAR(10) NOT NULL DEFAULT 'pending',
       `ext_member`       VARCHAR(255) DEFAULT NULL,
       PRIMARY KEY (`momento_id`, `momento_idmember`),
       KEY `momento_distribution_FI_2` (`momento_idmember`),
       KEY `accepted` (`accepted`, `ext_member`)
    )
  ENGINE=InnoDB
  DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>It has lots of data with many-to-one relations with two other tables with <code>ondelete=restrict</code> and <code>onupdate=restrict</code>.</p>
  
  <p>Now, I need to change the structure and introduce separate primary key in the table, while still keeping existing relations and data. For that, I executed the following query:</p>
  
  <pre><code>ALTER TABLE  `momento_distribution` ADD  `id` INT( 11 ) NOT NULL FIRST;
  ALTER TABLE  `momento_distribution` DROP PRIMARY KEY , ADD PRIMARY KEY (  `id` );
  </code></pre>
  
  <p>Unfortunately, my second query failed with the following error:</p>
  
  <blockquote>
    <p>1062 - Duplicate entry '0' for key 'PRIMARY'</p>
  </blockquote>
  
  <p>Can someone please point out the issue? I guess that the issue is the existing relation, but I don't want to lose the existing relation or data, that has several thousand rows. Is there any way to do this without losing data?</p>
  
  <p><strong>EDIT:</strong>
  By viewing data, I got that the newly created column has the  value '0' in it. Probably this is not allowing to change the Primary Key due to duplicate records (in new Primary Key)</p>
  
  <p>I have more than 8,000 rows, so I can't change it manually. Is there any way to assign <code>rowid</code> to a new Primary Key?</p>