在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'
希望能有所帮助!
1-进入/config/database.php,找到这些行
'mysql' => [
...,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
...,
'engine' => null,
]
并更改为:
'mysql' => [
...,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
...,
'engine' => 'InnoDB',
]
2-运行php artisan config:cache重新配置laravel
3-删除数据库中现有的表,然后再次运行php artisan migrate