SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes (SQL: alter table `roles` add unique `roles_name_guard_name_unique`(`name`, `guard_name`))
at F:\php\laravel-admin-cms-master\vendor\laravel\framework\src\Illuminate\Database\Connection.php:692
688▕ // If an exception occurs when attempting to run a query, we'll format the error
689▕ // message to include the bindings with SQL, which will make this exception a
690▕ // lot more helpful to the developer instead of just the database's errors.
691▕ catch (Exception $e) {
? 692▕ throw new QueryException(
693▕ $query, $this->prepareBindings($bindings), $e
694▕ );
695▕ }
696▕
1 F:\php\laravel-admin-cms-master\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485
PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes")
2 F:\php\laravel-admin-cms-master\vendor\laravel\framework\src\Illuminate\Database\Connection.php:485
PDOStatement::execute()
- 最有效解决办法
- 根据对应报错字段信息,直接设置该字段key长度即可,不需要添加Schema::defaultStringLength(191);如下图
Schema::create($tableNames['roles'], function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('title')->default ('');
$table->string('guard_name',50);
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
|