Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 + PostgreSQL: "Database [postgres] not configured." Error

Tags:

I'm trying to get started with Laravel + PostgreSQL and been following the database tutorial.

Unfortunately, after updating the database configuration file and running php artisan migrate, the following error appears:

  [InvalidArgumentException]   Database [postgres] not configured. 

What puzzles me is that I didn't specify the "postgres" database in the configuration, but another database I set through cPanel, say "example_database".


Here's some relevant parts of my /config/database.php configuration:

'default' => env('DB_CONNECTION', 'postgres') 

And inside the connections array of the same file:

'pgsql' => [         'driver'   => 'pgsql',         'host'     => env('DB_HOST', 'localhost'),         'database' => env('DB_DATABASE', 'example_database'), // This seems to be ignored         'username' => env('DB_USERNAME', 'example_username'),         'password' => env('DB_PASSWORD', 'example_password'),         'charset'  => 'utf8',         'prefix'   => '',         'schema'   => 'public'     ], 

The actual database credentials I'm using are working perfectly on my SQL Workbench client, so this seems to be a Laravel config problem. Any ideas? I have searched around for at least an hour to no avail.

like image 869
Francisco Hodge Avatar asked Jan 31 '16 08:01

Francisco Hodge


2 Answers

You have to enter your configuration in the .env file.

The configuration you made will only be loaded if they are not already defined in .env

You need to use pgsql instead of postgres.

DB_CONNECTION=pgsql DB_HOST=localhost DB_DATABASE=DB_NAME DB_USERNAME=USER DB_PASSWORD=PW  
like image 149
Fiete Avatar answered Oct 13 '22 07:10

Fiete


Laravel sometimes caches your configurations. If you run into this problem while everything looks alright try running

php artisan config:cache

like image 38
Bubunyo Nyavor Avatar answered Oct 13 '22 06:10

Bubunyo Nyavor