Laravel 5.6: Specified key was too long errorphp
在Laravel執行如下命令:數據庫
php artisan migrate
這是因爲Laravel5.6設置了數據庫默認編碼,如今的編碼默認爲「utf8mb4」(支持emoji),app
開始查看了官網是這麼說的:ide
「applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything.」編碼
若是MySQL版本大於5.7.7就能夠了,發現不行……spa
仍是報:code
[Illuminate\Database\QueryException]
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
))blog
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytesci
因此仍是按照Migrations的文檔老老實實的修改吧:文檔
打開 AppServiceProvider.php 文件寫入以下:
use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }
在從新執行
php artisan migrate
成功!!!