django.db.utils.OperationalError:致命:用户“”的对等身份验证失败

时间:2021-01-25 04:45:32

标签: python django postgresql

这几天来一直给我带来问题。

我有一个 django 应用程序,我正试图连接到一个elephantsql 数据库。

我的设置如下所示:

DATABASES = {'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'name_provided_by_elephantsql',
        'USER': 'name_provided_by_elephantsql',
        'PASSWORD': 'xxxxxxxxxxxxxxxx',
        'Host': 'ziggy.db.elephantsql.com',
        'PORT': '5432',
    }
}

每次尝试进行迁移时,都会出现以下错误:

`django.db.utils.OperationalError: FATAL:  Peer authentication failed for user "name_provided_by_elephantsql"

我的 pg_hba.conf 文件看起来像这样,但我尝试在 IPv6 下添加凭据,以及将几个“对等”更改为“md5”:

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

然后我尝试创建一个同名的psql用户,并用它创建了一个数据库:

createdb -U name_provided_by_elephantsql -h ziggy.db.elephantsql.com -p 5432

它返回了:

createdb: error: could not connect to database template1: FATAL:  no pg_hba.conf entry for host "174.45.58.218", user "name_provided_by_elephantsql", database "template1", SSL on
FATAL:  no pg_hba.conf entry for host "174.45.58.218", user "name_provided_by_elephantsql", database "template1", SSL off

在每次尝试之间重新启动 postgresql。我什至尝试清除 postgresql。最后我在重新安装 postgresql 之前尝试了这个:

sudo rm -Rf /etc/postgresql /var/lib/postgresql

谁能告诉我我可能遗漏了什么?

0 个答案:

没有答案