Laravel 5 + PostgreSQL:“未配置数据库[postgres]."错误

编程入门 行业动态 更新时间:2024-10-25 21:21:22
本文介绍了Laravel 5 + PostgreSQL:“未配置数据库[postgres]."错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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]."错误

本文发布于:2023-10-22 08:35:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516999.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   数据库   PostgreSQL   Laravel   postgres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!