#事象
Laravelのmigrationを掛けたかった。
しかし.envのDB名が間違っていたため、修正をかけたが、反映されず修正前のDB名でエラーが出た。
###変更前
.env
~
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=before #修正前
DB_USERNAME=root
DB_PASSWORD=
~
###変更後
.env
~
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=after #修正後
DB_USERNAME=root
DB_PASSWORD=
~
しかし、beforeのDB名でエラー出力されました。
$ php artisan migrate
Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown database 'before' (SQL: select * from information_schema.tables where table_schema = before and table_name = migrations and table_type = 'BASE TABLE')
at /Library/WebServer/Documents/laravel/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
Exception trace:
1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [1049] Unknown database 'before'")
/Library/WebServer/Documents/laravel/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31
2 PDOException::("SQLSTATE[HY000] [1049] Unknown database 'before'")
/Library/WebServer/Documents/laravel/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27
Please use the argument -v to see more details.
$
#解決策
config(?)のキャッシュクリア
$ php artisan config:clear
Configuration cache cleared!
参考:Laravel キャッシュクリア系コマンドなど
https://qiita.com/Ping/items/10ada8d069e13d729701