在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
我得到了这个错误尽管我已经有了(实际上因为我已经有了)
模式: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中进行更改,那么您需要在迁移中定义电子邮件字段的长度。只需将第一行代码替换为第二行。
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条目。