illuminate\database\queryexception sqlstate[42000]

gblwokeq  于 2021-06-20  发布在  Mysql
关注(0)|答案(3)|浏览(418)

我用的是拉威尔,当我想跑的时候 php artisan make:migrate 显示此错误:
illuminate\database\queryexception:sqlstate[42000]:语法错误或访问冲突:1071指定的键太长;最大密钥长度为767字节(sql:alter table users 添加唯一的 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 查看更多详细信息。

tpxzln5u

tpxzln5u1#

进入 App\Providers\AppServiceProvider 类并将引导方法更改为如下所示

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

2sbarzqh2#

找到config/database.php文件,并将字符集和排序规则从utf8mb4更改为utf8
'字符集'=>'utf8','排序规则'=>'utf8\u unicode\u ci',

osh3o9ms

osh3o9ms3#

去你的拉雷维尔项目和项目内打开 App\Providers\AppServiceProvider 类并更改引导方法,并在映像中添加新的模式show。
在顶部加上这一行 use Illuminate\Support\Facades\Schema; 替换此方法 public function boot() { Schema::defaultStringLength(191); }

相关问题