php - 拉维尔 5 + PostgreSQL : "Database [postgres] not configured." Error

标签 php postgresql laravel laravel-5 artisan-migrate

我正在尝试开始使用 Laravel + PostgreSQL 并一直在关注 database tutorial .

不幸的是,更新数据库配置文件并运行php artisan migrate后,出现如下错误:

  [InvalidArgumentException]
  Database [postgres] not configured.

令我困惑的是我没有在配置中指定“postgres”数据库,而是我通过cPanel设置的另一个数据库,比如“example_database”。


这是我的 /config/database.php 配置的一些相关部分:

'default' => env('DB_CONNECTION', 'postgres')

在同一文件的 connections 数组中:

'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'
    ],

我使用的实际数据库凭据在我的 SQL Workbench 客户端上运行良好,所以这似乎是 Laravel 配置问题。有任何想法吗?我已经搜索了至少一个小时,但无济于事。

最佳答案

您必须在 .env 文件中输入您的配置。

只有在 .env 中没有定义时才会加载您所做的配置

您需要使用 pgsql 而不是 postgres

DB_CONNECTION=pgsql
DB_HOST=localhost
DB_DATABASE=DB_NAME
DB_USERNAME=USER
DB_PASSWORD=PW 

关于php - 拉维尔 5 + PostgreSQL : "Database [postgres] not configured." Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35111806/

相关文章:

php - 无法通过 Mock 测试

php - Laravel 在 where 子句中加入 "and"和 "or"

php - 将 fpdf 输出存储在服务器中并在数据库中添加文件名

javascript - 我的 jQuery Ajax 无法与 PHP 配合使用

postgresql - Openbravo postgres 安装

python - SQLAlchemy:joinedload 子条款查询的 order_by(无)?

java - 如何为新用户订阅通知?

php - Laravel 在生产中以编程方式从 web.php 调用 artisan 命令

php - 如何处理全文搜索中的多个搜索条件和优先级

php - 查找 PHP 脚本输出字符串的位置