gpt4 book ai didi

php - 照亮\数据库\QueryException SQLSTATE[42000]

转载 作者:行者123 更新时间:2023-11-29 03:59:32 27 4
gpt4 key购买 nike

我正在使用 Laravel,当我尝试运行 php artisan make:migrate 时,它显示了这个错误:

Illuminate\Database\QueryException : 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))

at /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|

异常跟踪:

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:458

2 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);
}

关于php - 照亮\数据库\QueryException SQLSTATE[42000],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52623867/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com