php Laravel 5 + PostgreSQL:“未配置数据库 [postgres]。” 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35111806/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 + PostgreSQL: "Database [postgres] not configured." Error
提问by Francisco Hodge
I'm trying to get started with Laravel + PostgreSQL and been following the database tutorial.
我正在尝试开始使用 Laravel + PostgreSQL 并一直在关注数据库教程。
Unfortunately, after updating the database configuration file and running php artisan migrate
, the following error appears:
不幸的是,更新数据库配置文件并运行后php artisan migrate
,出现如下错误:
[InvalidArgumentException]
Database [postgres] not configured.
What puzzles me is that I didn't specify the "postgres" database in the configuration, but another database I set through cPanel, say "example_database".
令我困惑的是,我没有在配置中指定“postgres”数据库,而是通过 cPanel 设置的另一个数据库,说“example_database”。
Here's some relevant parts of my /config/database.php
configuration:
这是我的/config/database.php
配置的一些相关部分:
'default' => env('DB_CONNECTION', 'postgres')
And inside the connections
array of the same file:
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'
],
The actual database credentials I'm using are working perfectly on my SQL Workbench client, so this seems to be a Laravel config problem. Any ideas? I have searched around for at least an hour to no avail.
我使用的实际数据库凭据在我的 SQL Workbench 客户端上运行良好,所以这似乎是 Laravel 配置问题。有任何想法吗?我已经搜索了至少一个小时无济于事。
回答by Fiete
You have to enter your configuration in the .env
file.
您必须在.env
文件中输入您的配置。
The configuration you made will only be loaded if they are not already defined in .env
您所做的配置只有在尚未定义时才会加载 .env
You need to use pgsql
instead of postgres
.
您需要使用pgsql
而不是postgres
.
DB_CONNECTION=pgsql
DB_HOST=localhost
DB_DATABASE=DB_NAME
DB_USERNAME=USER
DB_PASSWORD=PW
回答by Bubunyo Nyavor
Laravel sometimes caches your configurations. If you run into this problem while everything looks alright try running
Laravel 有时会缓存您的配置。如果您在一切正常时遇到此问题,请尝试运行
php artisan config:cache
php artisan config:cache