The issue is that when executing the migrations with that command, it's executing Laravel's code outside of Docker. You'll need to run sail artisan migrate. See the docs - https://laravel.com/docs/8.x/sail#executing-artisan-commands
artisan migrate error with docker, laravel sail and postgresql
I am installing laravel sail with jetstream and postgresql. The installation is ok and the laravel container can see the postgresql one. I am showing data from the db in the controller. Until there everything ok. But when I try to install jetstream and do the table migration, it returns:
php artisan migrate:
could not translate host name "mycontainer" to address
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'mypgcontainer'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'mydb'),
'username' => env('DB_USERNAME', 'myuser'),
'password' => env('DB_PASSWORD', 'mypass'),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
It also doesn't work with DB_HOST 127.0.0.1 or localhost, because in that case laravel no longer connects with postgresql
SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "127.0.0.1"
The strange thing is that I can successfully connect from laravel to postgre and display data on screen with db_host 'mypgcontainer', but the migration with artisan return error
Any idea? Thanks!!
Please or to participate in this conversation.