我是一个db dummy,我试图为我的django项目设置PostgreSQL.为此,我也使用psycopg2.但数据库很复杂.就个人而言,如果有办法在一个地方掌握所有我的数据库和用户设置/信息,我想.所以我知道连接到什么以及如何连接(我仍在本地运行所以没有安全问题?).
然而,即使我连接到标准"admin"-user"postgres",我似乎也没有创建此数据库的"权限".使用我在安装下输入的密码("pw123").
Django-project(settings.py):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django',
'USER': 'postgres',
'PASSWORD': 'pw123',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Run Code Online (Sandbox Code Playgroud)
CMD - > python manage.py shell(导入django.db连接后)
>>> cursor = connection.cursor()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 165, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 138, in _cursor
self.ensure_connection()
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 133, in ensure_connection
self.connect()
File "C:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 133, …Run Code Online (Sandbox Code Playgroud)