This question already has an answer here:
I have a table Labels
with 2 columns:
+-------------+--------------+-------------+
| Column Name | Type | Key |
+-------------+--------------+-------------+
| id | integer | primary key |
| label | varchar(255) | unique |
+-------------+--------------+-------------+
In this table, I already have a record as the following:
id: 1, label: 'café'
And now I want to add more record as the following:
id: auto, label: 'cafe'
But when I try to insert, duplicate error appear
(1062, "Duplicate entry 'cafe' for key 'label_2'") [SQL: u'INSERT INTO vocabulary (label) VALUES (%s)'] [parameters: (u'cafe',)]
Could you guys help me in that case? Some more information about my database: character set: utf8, collate: utf8mb4_unicode_ci
UPDATE: create table
CREATE TABLE `labels` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`label` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `label_2` (`label`),
KEY `label` (`label`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
As far as
label
is unique key,you are not able to insert duplicate value in that column. As you want to distinguish betweencafé
andcafe
and then you need to use utf8_bin collation . Try below query.Hope this will helps.