Today, a self-growth primary key mysqlgt is set for a table in the project; ALTERTABLE 'users' CHANGE 'id''' id' INT (11) NOTNULLAUTO_INCREMENT; running reports
Today, a self-growth primary key mysqlgt is set for a TABLE in the project; alter table 'users' CHANGE 'id' id' INT (11) not null AUTO_INCREMENT; running reports
Set an auto-increment primary key for a table in the project today
Mysql> alter table 'users' CHANGE 'id''' id' INT (11) not null AUTO_INCREMENT;
ERROR 1062 (23000): Duplicate entry '1' for key 1
The original data in the table is as follows:
+ ---- + ------ +
| Id | name |
+ ---- + ------ +
| 0 | AAA |
| 1 | BBB |
| 2 | CCC |
+ ---- + ------ +-
Colleague tzngvi said that the data with id = 0 may be faulty. After the data with id = 0 is deleted, set auto-growth. The problem is solved.
Go to the MySQL official website and check again. AUTO_INCREMENT starts from 1 by default.
To start with an AUTO_INCREMENT value other than 1, you can set that value with create table or alter table, like this:
Mysql & gt; alter table tbl AUTO_INCREMENT = 100;