Q&A
実現したいこと
お疲れ様です。
今回お聞きしたいのはlaravelを使用してpostgresでマイグレーションを行いたいのですが、エラーが出ていることです。マイグレーションでエラーが出ているので、そちらを解決したいです。
前提
dockerを使用し、laradockにてLaravelの環境構築を行なっています。
データベースはpostgresqlを使用するのですが、プロジェクト作成、データベースへのマイグレーションを行う際、下記エラーが起こりマイグレーションができない状態です。
発生している問題・エラーメッセージ
ターミナルの表記 laradock@55efc171a703:/var/www$ php artisan migrate Illuminate\Database\QueryException SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE') at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712 708▕ // If an exception occurs when attempting to run a query, we'll format the error 709▕ // message to include the bindings with SQL, which will make this exception a 710▕ // lot more helpful to the developer instead of just the database's errors. 711▕ catch (Exception $e) { ➜ 712▕ throw new QueryException( 713▕ $query, $this->prepareBindings($bindings), $e 714▕ ); 715▕ } 716▕ } +33 vendor frames 34 artisan:37 Illuminate\Foundation\Console\Kernel::handle()
該当のソースコード
laradock
1### POSTGRES ############################################## 2 3POSTGRES_VERSION=alpine 4POSTGRES_DB=laradock 5POSTGRES_USER=laradock 6POSTGRES_PASSWORD=laradock 7POSTGRES_PORT=5432 8POSTGRES_ENTRYPOINT_INITDB=./postgres/docker-entrypoint-initdb.d 9 10### pgadmin ################################################## 11# use this address http://ip6-localhost:5050 12PGADMIN_PORT=8081 13PGADMIN_DEFAULT_EMAIL=pgadmin4@pgadmin.org 14PGADMIN_DEFAULT_PASSWORD=laradock
laravel
1DB_CONNECTION=pgsql 2DB_HOST=127.0.0.1 3DB_PORT=5432 4DB_DATABASE=laradock 5DB_USERNAME=laradock 6DB_PASSWORD=laradock
docker-compose.ymiは書き換えていません。
試したこと
DB_HOSTやDB_PORTを書き換える。
同様にlaradock内の情報を書き換え(ホストやユーザー名など)
変更後dockerの再起動、書き換え
そのほかネット検索にて書き換えや、ファイルを削除し新たにやり直すなどを行いました。
ちなみに以下をターミナルで試すとこのようなエラーが出てしまいます。恐らくデータベースに接続できていないものだと思います。
laradock@55efc171a703:/var/www$ php artisan tinker Psy Shell v0.11.12 (PHP 7.4.33 — cli) by Justin Hileman > DB::connection()->getConfig(); = [ "driver" => "pgsql", "host" => "127.0.0.1", "port" => "5432", "database" => "laradock", "username" => "laradock", "password" => "laradock", "charset" => "utf8", "prefix" => "", "prefix_indexes" => true, "schema" => "public", "sslmode" => "prefer", "name" => "pgsql", ] > DB::connection()->getPdo(); PDOException SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? >
追記
docker compose ps
でコンテナ内を確認し、
postgres-1 laradock-postgres-1 postgres
上記にホストを書き換えましたが、エラーが出て進みません。
docker compose ps laradock-docker-in-docker-1 laradock-nginx-1 laradock-pgadmin-1 laradock-php-fpm-1 laradock-postgres-1 laradock-workspace-1
エラー内容
error
1postgres-1 2could not translate host name "postgres-1" to address: Name or service not known. 3 4laradock-postgres-1 5 password authentication failed for user "laradock". 6 7pgadmin 8could not connect to server: Connection refused 9 Is the server running on host "pgadmin" (172.19.0.2) and accepting 10 TCP/IP connections on port 5432? 11 12postgres 13password authentication failed for user "laradock".
補足情報(FW/ツールのバージョンなど)
macbook air使用
初心者なので至らない点があるかもしれません。
必要なものがあればおっしゃってください。
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/02/27 03:50
2023/02/27 04:15