#1062-密钥1的重复条目'1'-找不到重复的条目 [英] #1062 - Duplicate entry '1' for key 1 - No duplicate entries found
问题描述
因此,当尝试向字段中添加自动增量时,它会出现#1062-密钥1的条目'1'重复.我尝试删除主键并重新添加它,效果很好(我认为如果有重复项,那不会吗?)
So when trying to add an autoincrement to a field it comes up with #1062 - Duplicate entry '1' for key 1 . I've tried removing the primary key and re-adding it and that works fine (which I assume wouldn't if there was duplicates?)
但是,当我尝试向字段中添加自动增量时,会引发错误.它为我提供了一个运行以下SQL的浏览选项:
But when I try to add an autoincrement to the field it throws an error. It gives me a browse option which runs the following SQL:
SELECT *
FROM `myTbl`
WHERE CONCAT_WS( "-", 11 ) = "1"
ORDER BY 11
LIMIT 0 , 30
但是,这将返回一个空结果集.表明没有重复项.因此,如果没有重复项,为什么我不能添加自动增量?
However this returns a empty result set.. suggesting there are no duplicates. So if there are no duplicates, how come i can't add an autoincrement?
推荐答案
此列是否有任何值为0
或NULL
的行? ALTER TABLE
可以导致对主键重新排序.在键为0的情况下,MySQL将尝试为其赋予值1,如果键1已经存在,它将失败.
Do you have any rows with value 0
or NULL
for this column? ALTER TABLE
can cause primary keys to be resequenced. In the case of a key of 0, MySQL will try to give it the value 1, which will fail if the key 1 already exists.
尝试将列中的任何0
或NULL
值更改为更高的值(并且未使用).
Try changing any 0
or NULL
values in the column to something higher (and unused).
这篇关于#1062-密钥1的重复条目'1'-找不到重复的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!