在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


当前回答

对我来说很有魅力!

将此添加到config/database.php

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

而不是

'engine' => 'null',

其他回答

推荐的解决方案是启用MySQL的innodb_large_prefix选项,这样你就不会陷入后续的问题。下面是如何做到这一点:

打开my.ini MySQL配置文件,并像这样在[mysqld]行下添加以下行。

[mysqld]
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_file_per_table = ON

之后,保存更改并重新启动MySQL服务。

如果需要回滚,然后重新运行迁移。


如果您的问题仍然存在,请转到数据库配置文件并设置

'engine' => null, to 'engine' => 'innodb row_format=dynamic'

希望能有所帮助!

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

Schema::defaultStringLength(191);

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

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

to

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

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

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

我用Laravel 5.7做的。

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

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

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

在database.php

-添加这一行:

引擎=>无害的ROW_FORMAT=动力,