在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


当前回答

将我的本地数据库服务器类型从“mariadb”更改为“mysql”,无需编辑任何Laravel文件就可以解决这个问题。

我按照本教程更改了我的db服务器类型:https://odan.github.io/2017/08/13/xampp-replacing-mariadb-with-mysql.html

其他回答

我不知道为什么上面的解和官方的解是相加的

Schema::defaultStringLength(191);

在AppServiceProvider中不适合我。 工作的是编辑config文件夹中的database.php文件。 只是编辑

'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',

to

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

它应该可以工作,尽管你将无法存储扩展的多字节字符,如表情符号。

这是一个丑陋的黑客,如果你想存储字符串在非英语语言,表情符号

我用Laravel 5.7做的。

不要忘记停止并再次启动服务器。

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

内部:

配置/ database.php

将这一行替换为mysql:

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

:

'engine' => null,

打开这个文件:/app/Providers/AppServiceProvider.php

并将此代码更新为我的图像:

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

首先删除本地主机中数据库的所有表

更改Laravel默认数据库(utf8mb4)在config/database.php文件中的属性为:

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

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

这里的方法是传递一个带有键名的第二个参数(一个短参数):

$table->string('my_field_name')->unique(null,'key_name');