.envとかに書いたデータベース接続情報(ユーザー名やパスワード)を変更したとき、普通にdocker compoes up -ddocker compoes downしても、マイグレーション時に次のようなエラーが発生する。

root@c18be2e9af87:/work# php artisan migrate

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [1045] Access denied for user 'yaju'@'192.168.96.3' (using password: YES) (SQL: select * from information_schema.tables where table_schema = laravel_local and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:703
    699▕         // If an exception occurs when attempting to run a query, we'll format the error
    700▕         // message to include the bindings with SQL, which will make this exception a
    701▕         // lot more helpful to the developer instead of just the database's errors.
    702▕         catch (Exception $e) {
  ➜ 703▕             throw new QueryException(
    704▕                 $query, $this->prepareBindings($bindings), $e
    705▕             );
    706▕         }
    707▕     }

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

下記のコマンドで解決できる。

docker-compose down --volumes
docker-compose up -d

それでも同じエラーが出る場合は?

多分、.envファイルを触ったつもりで.env.exampleだけを触ってるとかじゃないかな?

sqlのDockerfileのパスワードも変更したかチェックが必要。

参考にしたサイト

https://qiita.com/kter/items/cff39900a7c60aefd4a0

無制限に質問可能なプログラミングスクール!

万が一転職できない場合は、転職保障全額返金できるコースもあり!!

無制限のメンター質問対応

 

DMMウェブキャンプでプログラミングを学習しませんか?

独学より成長スピードをブーストさせましょう!

 

まずは無料相談から!

おすすめの記事