前言
作為一個 Laravel 開發者,在部署 Laravel 項目的時候總是會遇到這樣那樣奇怪的問題,每次遇到都要去 Google,實在是有點麻煩,就想自己整理一篇文章來記錄這些常見的問題。
常見問題一:Specified key was too long
file
在開發 Laravel 的項目時,有時我們需要對數據庫進行遷移,可是當我們在別的環境下跑 php artisan migrate
的時候經常會出現以下報錯:
[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))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
這時候我們把下面的代碼添加到 AppServiceProvider.php
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
常見問題二: This cache store does not support tagging
有時候我們在項目跑的好好的,突然使用 php artisan migrate
就會出現這個錯誤。
準確的說,這不是一個bug,詳情可以參考 這里,這是由于使用了 entrust 權限管理包導致,解決的話只需要修改 .env
文件,把 CACHE_DRIVER
改成 array
就可以啦。
常見問題三:The only supported ciphers are xxx and xxx with the correct key lengths
這時候先確認你的 .env
文件是否存在,如果沒有則創建,如果 .env
文件已經存在,則跑 php artisan key:generate
命令即可