1

我随机收到服务器错误,因为 Laravel 正在尝试连接到生产数据库,尽管事实上我已经.env设置了一个文件并且大部分时间它连接到正确的数据库。

这是我收到的错误:

[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)

为什么教义会尝试连接到错误的数据库?有时会在 dotenv 之前被实例化吗?

4

1 回答 1

0

第一的

您可以尝试清除或重新缓存您的配置 php artisan config:clearphp artisan config:cache

在运行迁移命令之前

第二

我在heroku上有这个问题。尝试从 heroku 的 sshheroku ps:exec环境运行迁移命令时。我在做:

heroku ps:execphp artisan migrate

但是在 heroku 应用程序中设置的环境变量对 laravel (env('DB_DATABASE')等)不可用。

为了解决这个问题,我不得不从 bash 运行迁移

heroku run bash

然后

php artisan migrate

于 2018-07-27T13:34:34.077 回答