My table structure:
CREATE TABLE `userimageview` (
`user_id` int(11) unsigned NOT NULL,
`image_id` int(11) unsigned NOT NULL,
`thumbnail_view` int(10) unsigned NOT NULL,
`fullsize_view` int(10) unsigned NOT NULL,
`point` int(10) unsigned NOT NULL,
KEY `everything` (`user_id`,`image_id`,`thumbnail_view`,`fullsize_view`,`point`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
The index that I’m going to add:
ALTER TABLE `userimageview` ADD UNIQUE `user_image` (`user_id` , `image_id`)
Result:
#1062 - Duplicate entry '1-11' for key 'user_image'
How should I add my UNIQUE index?
Your newly added
UNIQUEconstraint is failing because your table already contains duplicate rows that violate it. Locate the constraint violators with a query like the following. You won’t be able to add theUNIQUEindex as long as these rows are present.