error duplicate entry for key when creating new unique key mysql

error duplicate entry for key when creating new unique key mysql

If you got the above message when you try to add a new unique key on multiple column in mysql as

ALTER TABLE table_name ADD UNIQUE (col1, col2, col3);

Mysql would alert you if there is an already existing row in your table that is violating the newly added constraint.
Say you want to have uniqueness on col1 and col2 and assume col1 has value of “one” and col2 has value of “love”

Before this constraint you can have another row with the values of “one” and “love” for col1 and col2 respectively. But now that is not possible so you have to take care of that before applying

Configuring PHP + MySQL + Apache on Amazon EC2 Step by Step

Access MySQL from Host being on Vagrant

Setting new Vagrant machine for PHP-Mysql development

Using mysql keyword as column in Doctrine Entity – PHP

Connecting to Vagrant [PuPHPet] MySql from host

Points on Oracle MySQL Associate Certification Exam

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*