laravel migrate Syntax error or access violation: 1071 Specified key was too long

Laravel: 5.5.*

1
2
3
4
5
6
7
8
9
10
11
12
13
$ php artisan migrate
Migration table created successfully.

In Connection.php line 664:

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


In Connection.php line 458:

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000
bytes

使用的集成环境工具是phpStudy 2018 PHP7.2.10 NTS +Apache

修改config/database.php中的

1
2
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',

改为

1
2
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',

然后数据库的数据格式也修改一下

Reference
  1. Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes