在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
推荐的解决方案是启用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'
希望能有所帮助!
如果您想在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条目。