与PostgreSQL的Django连接:“Peer authentication failed” [英] Django connection to PostgreSQL: "Peer authentication failed"

查看:157
本文介绍了与PostgreSQL的Django连接:“Peer authentication failed”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ p>

这是我尝试访问我的Django管理员网站时收到的错误。我一直在使用MySQL数据库没有问题。我是PostgreSQL的新手,但决定切换,因为我最终计划用于这个项目的主机没有MySQL。



因此,我想我可以通过安装PostgreSQL的过程,运行一个 syncdb 并全部设置。



问题是我似乎无法让我应用程序连接到数据库。我可以通过我下载的命令行或桌面应用程序登录到PostgreSQL。只是不在脚本中



此外,我可以使用 manage.py shell 来访问数据库。



任何想法?

解决方案

我仔细观察了异常,注意到它必须做与我的连接设置。返回到 settings.py ,看到我没有主机设置。添加 localhost 和瞧。



我的settings.py没有MySQL数据库的HOST,但是我需要添加一个PostgreSQL来工作。



在我的情况下,我将 localhost 添加到 HOST 设置,它的工作。



这是$ DATABASES 部分从我的 settings.py

  DATABASES = {
'default':{
'ENGINE':'django.db.backends .postgresql_psycopg2',
'NAME':'< MYDATABASE>',
'USER':'< MYUSER>',
'PASSWORD':'< MYPASSWORD> b $ b'HOST':'localhost',#失踪的一块拼图
'PORT':'',#可选,我不需要这个,因为我使用标准端口
}
}


OperationalError at /admin/

FATAL:  Peer authentication failed for user "myuser"

This is the error I am receiving when I try to get to my Django admin site. I had been using MySQL database no problem. I am new to PostgreSQL, but decided to switch because the host I ultimately plan to use for this project does not have MySQL.

Therefore, I figured I could go through the process of installing PostgreSQL, run a syncdb and be all set.

Problem is that I cannot seem to get my app to connect to the database. I can login to PostgreSQL via command line or desktop app that I downloaded. Just not in the script.

Also, I can use manage.py shell to access the db just fine.

Any thoughts?

解决方案

I took a peek at the exception, noticed it had to do with my connection settings. Went back to settings.py, and saw I did not have a Host setup. Add localhost and voila.

My settings.py did not have a HOST for MySQL database, but I needed to add one for PostgreSQL to work.

In my case, I added localhost to the HOST setting and it worked.

Here is the DATABASES section from my settings.py.

DATABASES = { 
    'default': { 
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '<MYDATABASE>', 
        'USER': '<MYUSER>', 
        'PASSWORD': '<MYPASSWORD>', 
        'HOST': 'localhost', # the missing piece of the puzzle 
        'PORT': '', # optional, I don't need this since I'm using the standard port
    } 
}

这篇关于与PostgreSQL的Django连接:“Peer authentication failed”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆