我随机收到服务器错误,因为Laravel正在尝试连接到生产数据库,尽管我设置了.env
文件并且大部分时间它连接到正确的数据库。 / p>
以下是我收到的错误:
[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之前被证实吗?
答案 0 :(得分:0)
第一
您可以尝试清除或重新缓存您的配置
php artisan config:clear
或php artisan config:cache
在运行迁移命令之前
第二
我在heroku上遇到了这个问题。尝试从heroku的ssh heroku ps:exec
环境中运行迁移命令时。我在做:
heroku ps:exec
和
php artisan migrate
但是在laravel(env('DB_DATABASE')
等)中无法使用heroku应用程序中设置的env变量。
要解决此问题,我必须从bash运行迁移
heroku run bash
然后
php artisan migrate