[305]MYSQL 1062 error: duplicate entry ‘…’ for key ‘primary

Duplicate entry ‘… ‘For key ‘PRIMARY, the PRIMARY key data to be inserted into the data. It already exists. You can’t add it again. Example: Duplicate entry ‘0’ for key ‘PRIMARY refers to the data with a PRIMARY key value of 0 already exists, so the data with a PRIMARY key value of 0 can no longer be inserted.
Problem Solving:
Before the insert operation, you can perform the search operation SELECT for the primary key value, such as:
Perform an insert (0, “triple”) operation

insert into table(id,name) values(0,'Mr Three');

Duplicate entry ‘0’ for key ‘PRIMARY
can be added a judgment before insertion. If the PRIMARY key value is 0, it can be found, and it exists. If it cannot be found, the insert operation is performed.

select id from table where id = 0;

Read More: