OperationalError:致命错误:用户" UserName"

时间:2014-03-17 19:15:18

标签: database django postgresql authentication passwords

从GitHub下载项目后,尝试在本地运行它。我使用命令创建了一个数据库(我使用Postgres 9.1):

postgres = # CREATE NameUser django createDB WITH PASSWORD 'MyPass';
CREATE ROLE
postgres = # CREATE DATABASE DatabaseName OWNER NameUser;
CREATE DATABASE

然后在设置文件中我有这段代码:

DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.postgresql_psycopg2'
         'NAME': 'DatabaseName',
         'USER': 'NameUser'
         'PASSWORD': 'MyPass'
         'HOST': 'localhost',
         'PORT':'',
     }
}

命令后:./manage.py resetdb,收到:

OperationalError: FATAL: password authentication failed for user "NameUser"
FATAL: password authentication failed for user "NameUser"

我在stackoverflow上发现原因可能是文件pg_hba.conf。更改后看起来像这样:

# Database administrative login by Unix domain socket
local   all             postgres                                md5
# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

请求帮助。

1 个答案:

答案 0 :(得分:4)

尝试:

CREATE "NameUser" django createDB WITH PASSWORD 'MyPass';

请注意"NameUser"周围的双引号。这是因为PostgreSQL中的SQL标准标识符案例折叠。

相关问题