今天开始使用 Laravel5.4 做项目结果在执行 php artisan migrate 卡住了,总是报错:

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 文件,关键字搜索: utf8mb4 替换成 utf8 便可以了。

方法二

此方法原文链接:https://news.laravel-china.org/posts/544

修改 app/Providers/AppServiceProvider.php 文件:

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

来源于:https://58hualong.cn/blog/post/laravel54alter-table-users-add-unique-users_email_uniqueemail