While running the following queries on MySQL 5.6.39,
DROP TABLE IF EXISTS `sessions`;
CREATE TABLE `sessions` (
`id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`user_id` int(10) UNSIGNED DEFAULT NULL,
`ip_address` varchar(45) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`user_agent` text COLLATE utf8mb4_unicode_ci,
`payload` text COLLATE utf8mb4_unicode_ci NOT NULL,
`last_activity` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `sessions`
ADD UNIQUE KEY `sessions_id_unique` (`id`);
I get the following error :
However, if I remove the part that says COLLATE=utf8mb4_unicode_ci
, everything works fine. Why is this happening ?
The above query is an export from phpMyAdmin (MySQL version 5.7.22)
Best Answer
It seems that the
id
column isvarchar(255)
so from your config file enable theinnodb_large_prefix
on this instance of MySQL to resolve the problem but per the below, this explains why this is occurring from my interpretation.You can run
show variables
and see if theinnodb_large_prefix
if ON or OFF.Maximums and Minimums