我正在用postgresql DB运行python 2.7.3和django 1.5.1。在设置了一个简单的django应用程序后,我得到了一个OperationalError at FATAL: password authentication failed for user "postgres"。当我检查本地变量时,我发现psycopg2连接接受了错误的密码。我已经在django settings.py文件中指定了正确的密码。此外,manage.py syncdb运行良好,这个问题出现了2/3次。
pg_hba.conf中的所有身份验证方法都设置为md5 and settings.py has HOST:localhost
发布于 2014-07-19 14:28:50
不要使用用户postgres来做这件事。
为你的应用程序创建一个用户和一个db,并仅使用该用户。
su
su postgres
createuser -P <dbusername>
:type and re-type <dbuserpasswd>
createdb -O <dbusername> <dbname>检查你的pg_hba.conf
local all all md5重新启动postgresql服务器。
检查您的Django设置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'dbname', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'dbusername',
'PASSWORD': 'dbuserpasswd',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}重新启动您的http服务器。
https://stackoverflow.com/questions/24836995
复制相似问题