Laravel 8 项目 Syntax error or access violation: 1071 错误
Laravel 8.1 版本执行 php artisan migrate
出现错误
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException
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_uni
que`(`email`))
解决方法一:
升级 MySQL 到 5.7 以上版本。
解决方法二:
在项目 app/Providers/AppServiceProvider.php
中加入 Schema::defaultStringLength(191);
后 ,重新执行迁移。
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// 新加入的
Schema::defaultStringLength(191);
}