laravel5.7 migrate出错:1071 Specified key was too long; max key length is 767 bytes

使用最新版的laravel,mirgrate时出错,如下:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))

修改配置config/database.php

‘charset’ => ‘utf8mb4’,
‘collation’ => ‘utf8mb4_unicode_ci’,

‘charset’ => ‘utf8’,
‘collation’ => ‘utf8_unicode_ci’, // 这里我项目中使用的是utf8_general_ci

laravel默认使用了utf8mb4字符,如果mysql版本是5.7.7+则不会有此问题,否则应更改配置,我项目中使用的是mysql5.6。

点赞