ERROR 1062 (23000): Duplicate entry for key "PRIMARY"

I am trying to add a new column to sql table -

ALTER TABLE table1 ADD COLUMN column1 VARCHAR(400) DEFAULT NULL; 

But I get this error -

ERROR 1062 (23000): Duplicate entry '82133627' for key 'PRIMARY'

In table 1, we have only one primary key, and I ran the following command to see that the result is

 select * from table1 where <primary_key_field>='82133627'; 

Received 1 row in a set

 Primary key - primary_key_field int(11) NOT NULL 

In addition, I went through some answers to similar errors, where they suggested checking if the primary key has auto-increment. We have only one primary key in this table, and it does not have auto-increment.

How can i solve this?

+4
source share
1 answer

solution - you need to lock the table, and then after starting the request, unlock it

LOCK TABLES "table1" WRITE;

run the alter table command

then - UNLOCK TABLES;

+1
source

All Articles