简体   繁体   English

全新安装的 laravel 项目无法访问 postgresql 数据库,但可以执行 php migrate

[英]Fresh-installation laravel project can't access postgresql database but can do php migrate

I already asked a question about this 2 days ago, here are the links Got "password authentication failed for user" but in pgAdmin 3 its working我已经在 2 天前问了一个关于这个的问题,这里是链接得到了“用户密码验证失败”但是在 pgAdmin 3 中它的工作

But I still didn't get an answer to solve the problem.但是我仍然没有得到解决问题的答案。

So I tried to create a new laravel project, then edit the .env file, check if php artisan migrate can run.所以我尝试新建一个 laravel 项目,然后编辑.env文件,检查php artisan migrate是否可以运行。

After I run php artisan migrate it's running, so it means that my credentials to PostgreSQL database are correct right?在我运行php artisan migrate它正在运行之后,这意味着我对 PostgreSQL 数据库的凭据是正确的,对吗? if not it will tell you password authentication failed for user "postgres" , but I don't get any error at all, so I go to the next step.如果不是,它会告诉你password authentication failed for user "postgres" ,但我根本没有收到任何错误,所以我进入下一步。 Now after I make sure everything is OK i run php artisan make:auth , it's a success without error at all, so I go to the web browser then run the site, I clicked the register / login button, fill the fields, submit then, it's happened again the nightmare现在,在我确定一切正常后,我运行php artisan make:auth ,它完全没有错误就成功了,所以我转到网络浏览器然后运行该站点,我单击register / login按钮,填写字段,然后提交,又发生了噩梦

I got this message from the website我从网站上收到这条消息

SQLSTATE[08006] [7] FATAL: password authentication failed for user "postgres" FATAL: password authentication failed for user "postgres" (SQL: select count(*) as aggregate from "users" where "email" = test@test.com) SQLSTATE[08006] [7] 致命:用户“postgres”的密码身份验证失败 致命:用户“postgres”的密码身份验证失败(SQL:从“用户”中选择计数(*)作为聚合,其中“电子邮件”= test@test。 com)

Even though php artisan migrate run really well, so I've no idea why it's happening.尽管php artisan migrate运行得非常好,但我不知道为什么会这样。 Is there somebody that ever run into this problem before?以前有人遇到过这个问题吗? or maybe why it's happening?或者为什么会这样?

I already search all keywords that possible to fix this problem, but I can't found the answer, it's really stressed me out.我已经搜索了所有可能解决这个问题的关键字,但我找不到答案,这真的让我感到压力很大。

for the info I'm using:对于我正在使用的信息:

PostgreSQL 9.6.8 PostgreSQL 9.6.8

Laravel 5.6拉维尔 5.6

Ubuntu 17.10 Ubuntu 17.10

Edited: Here is my pg_hba.conf编辑:这是我的pg_hba.conf

在此处输入图像描述

Check your database.php file in config directory, and check the pgsql array.检查配置目录中的 database.php 文件,并检查 pgsql 数组。 If accessing DB credential values from.env not worked there, test it by directly putting credentials there.如果从 .env 访问数据库凭据值在那里不起作用,请通过直接将凭据放在那里进行测试。 hope it will help.希望它会有所帮助。 Artisan commands work by accessing the credentials from.env files directly,not from database.php that's why migration worked. Artisan 命令通过直接从 .env 文件访问凭据来工作,而不是从 database.php 访问凭据,这就是迁移有效的原因。

I had a similar problem, my generated password contained the character: '#'.我遇到了类似的问题,我生成的密码包含字符:'#'。 This made it a comment line, ignoring the rest of the password.这使它成为注释行,忽略密码的其余部分。 I just changed my password.我刚刚更改了密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM