List:General Discussion« Previous MessageNext Message »
From:Stefan Hinz Date:May 16 2003 12:22pm
Subject:Re[2]: ERROR 1062: Duplicate entry '1' for key 1
View as plain text  
Yvonne,

> I am getting the same problem. The autoincrementing primary key
> tinyint(3) indicates that the next number for it to use is 255 yet
> it has already used that number. I have rebuilt the table importing
> the data and it still gives me the 1062 error. I have erased the
> last record but it comes up to 255 and does not advance past it. It
> is in a MyISAM table.

The range of TINYINT UNSIGNED is from 0 to 255. Thus, if you have 256
rows in your table, your table is "full".

Solution: Change the column type to something bigger: SMALLINT
UNSIGNED (0 to 65535), INT UNSIGNED (0 to 4.2 billion), OR BIGINT
UNSIGNED:

ALTER TABLE mytbl MODIFY mycol INT UNSIGNED NOT NULL AUTO_INCREMENT;

See http://www.mysql.com/doc/en/Column_types.html for details.

Regards,
--
  Stefan Hinz <hinz@stripped>
  iConnect GmbH <http://iConnect.de>
  Heesestr. 6, 12169 Berlin (Germany)
  Telefon: +49 30 7970948-0  Fax: +49 30 7970948-3

[filter fodder: sql, mysql, query]

Thread
RE: ERROR 1062: Duplicate entry '1' for key 1Yvonne - At Your Service16 May
  • Re: ERROR 1062: Duplicate entry '1' for key 1Dan Nelson16 May
  • Re[2]: ERROR 1062: Duplicate entry '1' for key 1Stefan Hinz16 May
RE: ERROR 1062: Duplicate entry '1' for key 1Yvonne - At Your Service16 May