我正在使用 Laravel,当我尝试运行php artisan make:migrate它时显示此错误:
Illuminate\Database\QueryException : SQLSTATE[42000]: 语法错误或访问冲突:1071 指定的键太长;最大密钥长度为 767 字节(SQL:alter table
usersadd uniqueusers_email_unique(在 /Users/soksan/Desktop/TestLaravel/multiUsers/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Run Code Online (Sandbox Code Playgroud)
异常跟踪:
1
PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes")
/Users/soksan/Desktop/TestLaravel/multiUsers/vendor/laravel/framework/src/Illuminate/Database/Connection.php:4582
PDOStatement::execute()
/Users/soksan/Desktop/TestLaravel/multiUsers/vendor/laravel/framework/src/Illuminate/Database/Connection.php:458
请使用参数-v查看更多详细信息。
进入App\Providers\AppServiceProvider类并将启动方法更改为如下所示
public function boot()
{
Schema::defaultStringLength(191);
}
Run Code Online (Sandbox Code Playgroud)