title: Mysql - duplicate entry error for key with auto increment
body: <p>Why do I get an error of the form:</p>
  
  <p><code>Error in query: Duplicate entry '10' for key 1</code></p>
  
  <p>...when doing an INSERT statement like:</p>
  
  <p><code>INSERT INTO wp_abk_period  (pricing_id, apartment_id)  VALUES (13, 27)</code></p>
  
  <p>...with 13 and 27 being valid id-s for existing <code>pricing</code> and <code>apartment</code> rows, and the table is defined as:</p>
  
  <pre><code>CREATE TABLE `wp_abk_period` (
    `id` int(11) NOT NULL auto_increment,
    `apartment_id` int(11) NOT NULL,
    `pricing_id` int(11) NOT NULL,
    `type` enum('available','booked','unavailable') collate utf8_unicode_ci default NULL,
    `starts` datetime default NULL,
    `ends` datetime default NULL,
    `recur_type` enum('daily','weekly','monthly','yearly') collate utf8_unicode_ci default NULL,
    `recur_every` char(3) collate utf8_unicode_ci default NULL,
    `timedate_significance` char(4) collate utf8_unicode_ci default NULL,
    `check_in_times` varchar(255) collate utf8_unicode_ci default NULL,
    `check_out_times` varchar(255) collate utf8_unicode_ci default NULL,
    PRIMARY KEY  (`id`),
    KEY `fk_period_apartment1_idx` (`apartment_id`),
    KEY `fk_period_pricing1_idx` (`pricing_id`),
    CONSTRAINT `fk_period_apartment1` FOREIGN KEY (`apartment_id`) REFERENCES `wp_abk_apartment` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
    CONSTRAINT `fk_period_pricing1` FOREIGN KEY (`pricing_id`) REFERENCES `wp_abk_pricing` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
  </code></pre>
  
  <p>Isn't <code>key 1</code> <code>id</code> in this case and having it on <code>auto_increment</code> sufficient for being able to not specify it?</p>
  
  <p>Note: If I just provide an unused value for <code>id</code>, like <code>INSERT INTO wp_abk_period  (id, pricing_id, apartment_id)  VALUES (3333333, 13, 27)</code> it works fine, but then again, it is set as <code>auto_increment</code> so I shouldn't need to do this!</p>
  
  <hr>
  
  <p>Note 2: <strong>OK, this is a complete "twilight zone" moment:</strong> so after running the query above with the huge number for <code>id</code>, things started working normally, no more <code>duplicate entry errors</code>. <strong>Can someone explain me WTF was MySQL doing to produce this weird behavior?</strong></p>