2

I already have a table with some data in it. And now I want to add a new column "id" and make it a primary key. I'm using MySQL Workbench. So, I'm just adding a new key and then setting it as PK and NN. But for some reason, this apparently simple and straightforward operation doesn't work. I get:

ERROR 1062: Duplicate entry '0' for key 'PRIMARY'

Why is that?

1 Answer 1

1

You probably already have a field set as primary key in that table. I guess you would have to disable that field as PK and add the new id-column in the same statement.

Sign up to request clarification or add additional context in comments.

4 Comments

I don't have any other primary key.
@VisanCosmin Could you please add your SQL-Statement and column definitions of your table to your question?
I'm using mySql Workbench. I'm just selecting PK and NN and click apply. (I cannot insert a picture, because I don't have reputation at least 10.)
All I can think of is backing up the table data and recreate the table. Maybe this will help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.