Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation ‘=’

Searching for answers to an identical “Illegal mix of collations” error with conflicts between utf8_unicode_ci and utf8_general_ci.

I found that some columns in the database were not specifically collated utf8_unicode_ci. It seems mysql implicitly collated these columns utf8_general_ci.

Specifically, running a ‘SHOW CREATE TABLE table1’ query outputted something like the following:

| table1 | CREATE TABLE `table1` (
`id` int(11) NOT NULL,
`col1` varchar(4) CHARACTER SET utf8 NOT NULL,
`col2` int(11) NOT NULL,
PRIMARY KEY (`photo_id`,`tag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |

Note the line ‘col1’ varchar(4) CHARACTER SET utf8 NOT NULL does not have a collation specified. I then ran the following query:

ALTER TABLE table1 CHANGE col1 col1 VARCHAR(4) CHARACTER SET utf8
COLLATE utf8_unicode_ci NOT NULL;

This solved my “Illegal mix of collations” error. Hope this might help someone else out there.

or

ALTER DATABASE `db` CHARACTER SET utf8 COLLATE utf8_general_ci;
or
COLLATE utf8_unicode_ci;