我现在正在学习 Django,并且正在一步一步地学习Django 书。
当我继续第 5 章将我的 Django 项目连接到我的数据库时,我无法连接它。我得到错误:
FATAL: password authentication failed for user "postgres"
这是代码:
settings.py
配置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'postgis', # Or path to database file if using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'XXXXXXX', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '8904', # Set to empty string for default. Not used with sqlite3.
}
}
但是当我使用这些代码在 Python shell 中测试连接和设置时:
from django.db import connection
cursor=connection.cursor()
外壳回复错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "E:\Python27\lib\site-packages\django-1.4.1- py2.7.egg\django\db\backends\__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "E:\Python27\lib\site-packages\django-1.4.1-py2.7.egg\django\db\backends\
postgresql_psycopg2\base.py", line 177, in _cursor
self.connection = Database.connect(**conn_params)
File "E:\Python27\lib\site-packages\psycopg2\__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
OperationalError: FATAL: password authentication failed for user "postgres"
然后我重新安装了 PostgreSQL 和 pycopg2 包。我启动 pgAdminIII 运行服务器并连接到数据库,然后我在 python shell 中运行相同的代码,但问题仍然存在。
需要帮忙!