在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
我只是把这个答案加在这里,因为这对我来说是最快的解决方法。只需要将默认的数据库引擎设置为'InnoDB'
/ config / database.php
'mysql' => [
...,
...,
'engine' => 'InnoDB',
]
然后运行PHP artisan config:cache来清除和刷新配置缓存
编辑:
这里找到的答案可能解释了这一事件背后的原因
我不知道为什么上面的解和官方的解是相加的
Schema::defaultStringLength(191);
在AppServiceProvider中不适合我。
工作的是编辑config文件夹中的database.php文件。
只是编辑
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
to
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
它应该可以工作,尽管你将无法存储扩展的多字节字符,如表情符号。
这是一个丑陋的黑客,如果你想存储字符串在非英语语言,表情符号
我用Laravel 5.7做的。
不要忘记停止并再次启动服务器。