在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


当前回答

最干净的解决方案是去你的数据库并更改:

default_storage_engine to InnoDB

你很可能有MyISAM。

其他回答

如果您想在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条目。

腔:

添加到。env文件

DB_ENGINE=InnoDB

尝试使用默认字符串长度125 (MySQL 8.0)。

defaultStringLength (125)

对于不想更改AppServiceProvider.php的人。 (在我看来,仅仅为了迁移而更改AppServiceProvider.php是一个坏主意)

您可以将数据长度添加回database/migrations/下的迁移文件,如下所示:

create_users_table.php

$table->string('name',64);
$table->string('email',128)->unique();

create_password_resets_table.php

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

在laravel

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

/ config / database.php

'engine' => 'InnoDB',

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

PHP工匠数据库:擦

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

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