【发布时间】:2014-12-09 18:52:43
【问题描述】:
我是一个 db 假人,我正在尝试为我的 django 项目设置 PostgreSQL。为此,我还使用 psycopg2。数据库虽然复杂。就个人而言,我希望有一种方法可以在一个地方获取我所有的数据库和用户设置/信息。所以我知道什么连接以及如何连接(我仍在本地运行,所以没有安全问题?)。
但是,即使我连接到标准的“admin”-用户“postgres”,我似乎也没有创建此数据库的“权限”。使用我在安装时输入的密码(“pw123”)。
Django 项目(settings.py):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django',
'USER': 'postgres',
'PASSWORD': 'pw123',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
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, in ensure_connection
self.connect()
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 122, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Python27\lib\site-packages\django\db\backends\postgresql_psycopg2\base.py", line 134, in get_new_connection
return Database.connect(**conn_params)
File "C:\Python27\lib\site-packages\psycopg2-2.5.4-py2.7-win32.egg\psycopg2\__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: FATAL: database "django" does not exist
我在安装过程中做错了吗?我可以纠正吗?我应该考虑重新安装所有东西吗?我该怎么办?数据库让我很困惑:P
【问题讨论】:
-
你必须先创建数据库。
-
是的,但是怎么做?此外,我想我已经读过,如果我没有,这个方法会创建一个..我不是通过这样做创建名为“django”的数据库吗,因为这就是我想要的(!?):P
标签: django database postgresql psycopg2