在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默认数据库(utf8mb4)在config/database.php文件中的属性为:

'charset' => 'utf8', 'collation' => 'utf8_unicode_ci',

之后 更改我的本地数据库属性utf8_unicode_ci。 PHP工匠迁移 没关系。

其他回答

我得到了这个错误尽管我已经有了(实际上因为我已经有了) 模式:defaultStringLength (191);在AppServiceProvider.php文件中。

原因是我试图在我的一个迁移中设置一个高于191的字符串值:

Schema::create('order_items', function (Blueprint $table) {
    $table->primary(['order_id', 'product_id', 'attributes']);
    $table->unsignedBigInteger('order_id');
    $table->unsignedBigInteger('product_id');
    $table->string('attributes', 1000); // This line right here
    $table->timestamps();
});

删除1000或将其设置为191解决了我的问题。

对于不想更改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();

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

第一个解决方案是:

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

第二个解决方案是:

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

古德勒克

与其设置长度限制,我建议以下方法,这对我来说很有效。

内部:

配置/ database.php

将这一行替换为mysql:

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

:

'engine' => null,

对于可能遇到这种情况的任何人,我的问题是我正在创建一个类型为字符串的列,并试图使它->unsigned()当我想让它是一个整数时。