0

当我尝试auto_increment在 phpmyadmin 中的列上启用时,但我总是收到此错误:

#1062 - Duplicate entry '1' for key 1 

有问题的列是 PK 和一个 INT。它已经有几行了。因此,我尝试了以下方法:

ALTER TABLE Persons AUTO_INCREMENT=7

这应该将自动递增设置为从 7 开始,因此跳过该行中已经存在的 0 到 6 ......但它不起作用。或者这就是理论。

我究竟做错了什么?


更新:

我已尝试删除列上的 PK 索引并运行将列设置为NULL. 一切都设置为NULL。然后我尝试添加auto increment,但出现以下错误:#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key. 我尝试再次添加 PK 索引并获得以下内容#1062 - Duplicate entry '0' for key 1。啊。

4

2 回答 2

1

尝试这个: alter table Persons modify id integer unsigned primary key auto_increment;

id 是感兴趣的列

于 2012-02-20T12:06:07.043 回答
0

尝试向auto_increment现有表中添加一个时,您需要确保表中已有的所有键值都是唯一的。

将列值设置为NULL应该可以。然后,mySQL 将使用自动增量值自动填充值。

于 2012-02-20T11:39:58.173 回答