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

Unfortunately, after updating the database configuration file and running php artisan migrate, the following error appears:

  [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".


Here's some relevant parts of my /config/database.php configuration:

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

And inside the connections array of the same file:

'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.

推荐答案

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

The configuration you made will only be loaded if they are not already defined in .env

You need to use pgsql instead of postgres.

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

Laravel相关问答推荐

Nuxt 3获取多部分表单数据上传不起作用

为什么在Blade 文件中输出用户通知时出现错误?

在Vite list 中找不到文件:Resources/scss/hrms.scss.如何使用LARAVEL VITE解决这个问题?

Laravel:在 PHPUnit 的覆盖率报告中包含文件夹(如果在 app/ 文件夹之外)?

Laravel phpunit 测试失败并出现 PDOException:SQLSTATE[HY000]:一般错误:1 接近0:语法错误

在 Laravel 包中的路由上使用显式或隐式模型绑定

Laravel Livewire 组件在刷新后不会自动刷新/重新加载

Laravel 错误ReflectionException-类 App\Http\Kernel 不存在

Laravel 5.4 存储:下载文件.文件不存在,但显然存在

Laravel 5 make:控制器在应用程序文件夹而不是控制器文件夹中创建控制器

如何在 Laravel 5.5 的 FormRequest 类中返回自定义响应?

CRON 作业(job) - LARAVEL - 输出

如何在 laravel blade中进行一次性推送

413请求实体在laravel homestead for windows中太大的nginx服务器

如何将Carbon 转换为字符串,只取日期?

在 Laravel 5 中找不到类App\Http\Controllers\Artisan

laravel 搜索多个以空格分隔的单词

laravel 如何读取 app/config/app.php 调试变量

Laravel 表:只能有一个自动列,并且必须定义为键

搜索结果分页 laravel 5.3