Reputation: 9
I have a MySQL table in which already store many important data, but it's doesn't have any primary key and auto increment ids. Now I want to set primary key on my ID column but I don't need a Auto_increment ids in any column in my table. So when I try to set primary key on ID column then this error is coming "ERROR 1062 (23000): Duplicate entry '' for key 'PRIMARY'"
So..How can I solve this prob. Can I set Primary key without Auto_increment ids?
Upvotes: 0
Views: 9987
Reputation: 3417
Just restore the dump with -f (--force) or --insert-ignore to carry the process it will encounter the errors and proceeds the dump or insert
mysql -u root -p -f <NAME OF DB> < <BACKUP DB>.sql
Upvotes: 3
Reputation: 51868
This is not a problem of auto_increment. You have two or more rows with the same value in this column. Therefore this column can not be used as primary key. It needs to be unique. Remove redundant data or introduce another column as primary key, maybe an auto_increment column? ;)
Upvotes: 0
Reputation: 69440
You have more than one entry in your table vith id blank. you should chnage your id's so that they are unique and than you add add a primary key constraint.
Upvotes: 0