我正在尝试开始使用 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/