在Laravel 5.4上使用php artisan make:auth迁移错误

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter tabl e users add unique users_email_unique(email)) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes


当前回答

这很常见,因为Laravel 5.4将默认数据库字符集更改为utf8mb4。你要做的是:编辑你的App\Providers.php,把这段代码放在类声明之前

use Illuminate\Support\Facades\Schema;

另外,将此添加到'boot'功能 模式:defaultStringLength (191);

其他回答

只要在/etc/mysql/mariadb.conf.d/50-server.cnf或其他配置文件中写几行:

innodb-file-format=barracuda
innodb-file-per-table=ON
innodb-large-prefix=ON
innodb_default_row_format = 'DYNAMIC'

和sudo服务mysql重启

https://stackoverflow.com/a/57465235/778234

查看文档:https://dev.mysql.com/doc/refman/5.6/en/innodb-row-format.html

据官方Laravel 7日报道。X文档,可以很容易地解决这个问题。

更新你的/app/Providers/AppServiceProvider.php包含:

use Illuminate\Support\Facades\Schema;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Schema::defaultStringLength(191);
}

或者,您可以为您的数据库启用innodb_large_prefix选项。有关如何正确启用此选项的说明,请参阅数据库的文档。

如果您想在AppServiceProvider中进行更改,那么您需要在迁移中定义电子邮件字段的长度。只需将第一行代码替换为第二行。

create_users_table

$table->string('email')->unique();
$table->string('email', 50)->unique();

create_password_resets_table

$table->string('email')->index();
$table->string('email', 50)->index();

在成功更改之后,您可以运行迁移。 注意:首先你必须从数据库中删除(如果你有)users表,password_resets表,并从迁移表中删除users和password_resets条目。

在laravel

首先将默认数据库引擎设置为“InnoDB on”

/ config / database.php

'engine' => 'InnoDB',

然后运行PHP artisan config:cache来清除和刷新配置缓存。

PHP工匠数据库:擦

修改/config/database.php中mysql数组的这些值,如下所示 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 然后

PHP工匠迁移 这是所有!迁移表创建成功。

我添加了两个对我有用的解决方案。

第一个解决方案是:

在config目录下打开database.php文件。 将'engine' =>修改为'engine' => 'InnoDB' 这对我很管用。

第二个解决方案是:

在config目录下打开database.php文件。 2.编辑'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 来 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci',

古德勒克