I add a read and write database connection in the current laravel application, like this:
'mysql' => [
'read' => [
'host' => [
env('DB_HOST_READONLY', '127.0.0.1'),
],
],
'write' => [
'host' => [
env('DB_HOST', '127.0.0.1'),
],
],
'sticky' => true,
'driver' => 'mysql',
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
...
Because I have CI/CD setup on Gitlab I get this error:
cp .env.example .env
php artisan migrate:refresh --seed
In Connection.php line 692:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = oauth_test and table_name = migrations and table_type = 'BASE TABLE')
In Connector.php line 70:
SQLSTATE[HY000] [2002] Connection refused
I also add in .env.example file DB_HOST_READONLY parameter which is also 127.0.0.1, the same as DB_HOST parameter. Without this change, all works well. Can you help me or have some idea? Be free to ask if you need something more.
CodePudding user response:
You don't have a database runing on 127.0.0.1
in your CI environment so it fails to run migrations.
CodePudding user response:
As explained by AlexD, Your Gitlab machine runs on CI env, which is another Server to build and package your application
For you tests/access to DB on you CI build , you must give the URL or the ip of the machine which host the database which can be injected in your env variable of you gitlab ci without hard coded in your .env file.