【问题标题】:Laravel/Doctrine randomly tries to connect to production databaseLaravel/Doctrine 随机尝试连接到生产数据库
【发布时间】:2018-02-17 08:48:24
【问题描述】:

我随机收到服务器错误,因为 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 之前被实例化吗?

【问题讨论】:

    标签: php laravel doctrine laravel-doctrine


    【解决方案1】:

    第一

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

    在运行迁移命令之前

    其次

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

    heroku ps:execphp artisan migrate

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

    要解决这个问题,我必须从 bash 运行迁移

    heroku run bash

    然后

    php artisan migrate

    【讨论】:

      猜你喜欢
      • 2021-10-29
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 1970-01-01
      • 2023-03-24
      • 2016-02-04
      • 1970-01-01
      • 2018-10-15
      相关资源
      最近更新 更多