#1062 – Duplicate entry ” for key ‘unique_id’ When Trying to add UNIQUE KEY (MySQL)

The error says it all:

Duplicate entry '' 

So run the following query:

SELECT unique_id,COUNT(unique_id)
FROM yourtblname
GROUP BY unique_id
HAVING COUNT(unique_id) >1

This query will also show you the problem

SELECT *
FROM yourtblname
WHERE unique_id=''

This will show you where there are values that have duplicates. You are trying to create a unique index on a field with duplicates. You will need to resolve the duplicate data first then add the index.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)