postgresql auth django(用户“ BlogAdmin2”的密码身份验证失败)

时间:2019-03-19 18:38:42

标签: python django postgresql

我遵循了Digital Ocean发布的教程:https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04#create-and-configure-a-new-django-project(如何在ubuntu上使用postgres nginx和gunicorn设置django) 我用网站创建了一个git hub私有仓库,当我使用以下命令创建了postgresql数据库时:

CREATE DATABASE PiaBlog;
CREATE USER BlogAdmin WITH PASSWORD 'Andrei1234';
ALTER ROLE BlogAdmin SET client_encoding TO 'utf8';
ALTER ROLE BlogAdmin SET default_transaction_isolation TO 'read committed';
ALTER ROLE BlogAdmin SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE PiaBlog TO BlogAdmin;
\q

这是我的django数据库配置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'PiaBlog',
        'USER': 'BlogAdmin',
        'PASSWORD': 'Andrei1234,',
        'HOST': 'localhost',
        'PORT': '',
    }
}

当我运行python manage.py migrate时,我得到了:

django.db.utils.OperationalError: FATAL:  password authentication failed for user "BlogAdmin2"
FATAL:  password authentication failed for user "BlogAdmin2"

有人知道为什么会出现这个问题吗?我花了一个小时来寻找打字错误,但从未找到。

然后我创建了一个新用户,但出现此错误:

django.db.utils.OperationalError: FATAL:  password authentication failed for user "blog_admin"
FATAL:  password authentication failed for user "blog_admin"

这就是我所做的:

CREATE DATABASE blogdb;
CREATE USER blog_admin WITH PASSWORD 'testing1234';
ALTER ROLE blog_admin SET client_encoding TO 'utf8';
ALTER ROLE blog_admin SET default_transaction_isolation TO 'read committed';
ALTER ROLE blog_admin SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE blogDB TO blog_admin;
\q

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'blogdb',
        'USER': 'blog_admin',
        'PASSWORD': 'testing123',
        'HOST': 'localhost',
        'PORT': '',
    }
}

1 个答案:

答案 0 :(得分:0)

该逗号应该在您的密码中吗?

'PASSWORD': 'Andrei1234,',