1

I'm randomly getting server errors because Laravel is trying to connect to the production database, despite the fact that I have a .env file set up and a majority of the time it connects to the correct database.

Here is the error I am receiving:

[2018-02-17 08:05:54] production.ERROR: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = forge and table_name = settings) {"exception":"[object]
(Illuminate\\Database\\QueryException(code: 1045): SQLSTATE[HY000]
[1045] Access denied for user 'forge'@'localhost' (using password: NO)
(SQL: select * from information_schema.tables where table_schema = forge and table_name = settings) at C:\\wamp64\\www\\projects\\infusedx\\vendor\\laravel\\framework\\src\\Illuminate\\Database\\Connection.php:664,
Doctrine\\DBAL\\Driver\\PDOException(code: 1045): SQLSTATE[HY000]
[1045] Access denied for user 'forge'@'localhost' (using password: NO)
at
C:\\wamp64\\www\\projects\\infusedx\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Driver\\PDOConnection.php:47,
PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for
user 'forge'@'localhost' (using password: NO) at
C:\\wamp64\\www\\projects\\infusedx\\vendor\\doctrine\\dbal\\lib\\Doctrine\\DBAL\\Driver\\PDOConnection.php:43)

Why would doctrine be trying to connect to the wrong database? Is it being insantiated before dotenv sometimes?

Iter Ator
  • 8,226
  • 20
  • 73
  • 164
kjdion84
  • 9,552
  • 8
  • 60
  • 87

1 Answers1

0

First

You can try clear or re-cache your configurations php artisan config:clear or php artisan config:cache

before running your migration commands

Secondly

I had this issue on heroku. When trying to run migration commands from heroku's ssh heroku ps:exec environment. i was doing:

heroku ps:exec and php artisan migrate

but the env variables set in the heroku app isn't available to laravel (env('DB_DATABASE'), etc).

To fix this, i had to run the migrations from the bash

heroku run bash

then

php artisan migrate

Emeke Ajeh
  • 933
  • 1
  • 10
  • 16