You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel提示Database [postgres]未配置,附配置文件求解决

Fixing the "database [postgres] not configured" Error in Laravel

Hey there, let's get this connection issue sorted out for you. Looking at your configs, I can spot a couple of straightforward fixes that should resolve the error:

1. Mismatched Connection Name in database.php

Your database.php sets 'default' => 'postgres', but your PostgreSQL connection configuration is nested under the 'pgsql' key. Laravel looks for a connection entry that exactly matches the default name you specify—right now it's searching for a 'postgres' key that doesn't exist, hence the error.

Fix:
Stick to Laravel's default convention by updating the default value to match the connection key:

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

Alternatively, you could rename the connection key to 'postgres' to match your current default setting, but the first option is more consistent with how Laravel is set up out of the box.

2. Incorrect Environment Variable Reference

In your pgsql connection config, you have 'username' => env('postgres', '')—this is trying to pull an environment variable named postgres, which isn't defined in your .env file (your username variable is DB_USERNAME).

Fix:
Update the username (and double-check your password line too) to reference the correct .env variables:

'username' => env('DB_USERNAME', ''),
'password' => env('DB_PASSWORD', ''),

3. Clear Configuration Cache (Important!)

After making these changes, clear Laravel's config cache to ensure the new settings are loaded instead of cached old values:

php artisan config:clear

Once you apply these tweaks, your PostgreSQL connection should work without that error popping up.

内容的提问来源于stack exchange,提问作者Lyes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:09:47