0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed:

Posted at

Laravelのマイグレーション時に発生したエラーとその解決策

発生したエラー

php artisan migrate

laravelで上のようにマイグレーションをしようとしたら以下のようなエラーに出会した。

スクリーンショット 2025-03-13 22.11.53.png

この問題は、Laravel の migrate コマンド実行時に MySQL データベースに接続できないことが原因のようだ。エラーメッセージ php_network_getaddresses: getaddrinfo for mysql failed は、mysql というホスト名が解決できないことを示している。

解決策

結論から述べると以下のように実行コードを変更したらうまくいった。

./vendor/bin/sail artisan migrate --path=database/migrations/2025_03_08_132630_add_test_column.php

2025_03_08_132630_add_test_column.phpの部分は任意のファイル名にして個別でマイグレーションを行うと以下のようにうまくいった。

スクリーンショット 2025-03-14 17.13.18.png

データベースの問題なので、.envファイルのDB_HOSTの名前が問題かもしれないが今後の課題とする。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?