我正在尝试使用Laravel + PostgreSQL,并一直遵循数据库教程.
I'm trying to get started with Laravel + PostgreSQL and been following the database tutorial.
不幸的是,更新数据库配置文件并运行php artisan migrate后,出现以下错误:
Unfortunately, after updating the database configuration file and running php artisan migrate, the following error appears:
[InvalidArgumentException] Database [postgres] not configured.让我感到困惑的是,我没有在配置中指定"postgres"数据库,而是通过cPanel设置的另一个数据库,例如"example_database".
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".
这是我的/config/database.php配置的一些相关部分:
Here's some relevant parts of my /config/database.php configuration:
'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配置问题.有任何想法吗?我搜索了至少一个小时,但无济于事.
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.
推荐答案您必须在.env文件中输入配置.
You have to enter your configuration in the .env file.
只有在.env
您需要使用pgsql而不是postgres.
DB_CONNECTION=pgsql DB_HOST=localhost DB_DATABASE=DB_NAME DB_USERNAME=USER DB_PASSWORD=PW更多推荐
Laravel 5 + PostgreSQL:“未配置数据库[postgres]."错误
发布评论