【问题标题】:Django-postgresql: psycopg2 dsn takes wrong passwordDjango-postgresql:psycopg2 dsn 输入错误密码
【发布时间】:2014-09-10 07:11:22
【问题描述】:
我正在运行 python 2.7.3 和 django 1.5.1 和 postgresql DB。在设置了一个简单的 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 具有HOST:localhost
【问题讨论】:
标签:
python
django
postgresql
psycopg2
【解决方案1】:
不要使用用户 postgres 来执行此操作。
为您的应用创建一个用户和一个数据库,并仅使用该用户。
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 服务器。