laravel 5.4 版本改变默认的数据库字符集为utf8mb4。如果你运行MySQL v5.7.7或者更高版本,则不需要做任何事情。
否则你在运行 migrations 命令时,可能会碰到下面这个错误:
1
|
[IlluminateDatabaseQueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email)) SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
|
1
|
Schema::defaultStringLength(200);
|
完整的AppServerProvider.php文件代码如下:
1
|
<?php namespace AppProviders; use IlluminateSupportServiceProvider; use IlluminateSupportFacadesSchema; class AppServiceProvider extends ServiceProvider { public function boot() { Schema::defaultStringLength(200); } public function register() { // } }
|