rs1290
rs1290

Reputation: 61

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 am getting this error -

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

In table1, we just have one primary key, and i ran the following command to see what's the result -

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

Got 1 row in set

Primary key - primary_key_field int(11) NOT NULL

Also, i went thru some of the responses for similar errors where they suggested to check if the primary key has auto-increment. We just have one primary key in this table, and it does not have auto-increment.

How can I solve this?

Upvotes: 4

Views: 4374

Answers (1)

rs1290
rs1290

Reputation: 61

solution - need to lock table, and then after running the query unlock it

LOCK TABLES "table1" WRITE;

run the alter table command

then - UNLOCK TABLES;

Upvotes: 1

Related Questions