26

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.

hodgef
  • 1,416
  • 2
  • 19
  • 31

3 Answers3

62

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 
Jerry U
  • 618
  • 9
  • 22
Fiete
  • 1,332
  • 11
  • 12
  • Thanks for the explanation. I've made the change in the .env file but the error is the same. Is there something else I'm missing? – hodgef Jan 31 '16 at 08:36
  • 1
    @FranciscoH. I just updated my answer. rename `postgress` to `pgsql`. – Fiete Jan 31 '16 at 08:40
  • Setting `DB_CONNECTION=pgsql` gives the following error: `could not find driver`. I set it as `DB_CONNECTION=postgres` based on this answer http://stackoverflow.com/a/25336292/1467941 – hodgef Jan 31 '16 at 08:41
  • 2
    Did you also have checked if the pdo postgress driver is installed and loaded correctly? – Fiete Jan 31 '16 at 08:45
  • That was exactly the issue, Fiete. Also, `DB_CONNECTION=pgsql` works now after installing pdo_pgsql. Silly mistake on my part. Thanks a lot! – hodgef Feb 01 '16 at 01:02
  • 1
    "You need to use pgsql instead of postgres." This was hard to find information! Thanks. – Brian Peterson Feb 21 '19 at 20:08
  • 1
    This answer works for me perfectly. I am using ssh with homestead on a Linux machine. – Kelvin Omereshone Jun 23 '20 at 13:27
7

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

php artisan config:cache

Bubunyo Nyavor
  • 2,511
  • 24
  • 36
2

I know this is an old question and it already has an answer; however, here is an small explanation why:

If you check your database.php in the config directory, you will see that you have few connections types, including pgsql. So, the key have to match to the DB_CONNECTION in .env file. You can definitely replace pqsql connection key with postgres, and it will work on the same way.

However, I would recommend replacing the value DB_CONNECTION, instead of modifying the config.

DB_CONNECTION=pgsql
Cristea
  • 913
  • 10
  • 15