【发布时间】:2013-02-02 18:51:32
【问题描述】:
我目前正在玩 django,并希望将其用作我的数据库 postgresql:
这些是我在设置文件中的配置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'django', # Or path to database file if using sqlite3.
'USER': 'postgres', # Not used with sqlite3.
'PASSWORD': 'postgres', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
}
}
我也尝试过使用 postgresql_psycopg2 并安装了 psycopg2(http://www.stickpeople.com/projects/python/win-psycopg/)。
你知道配置有什么问题吗?
更新:
错误:
> File
> "C:\Python27\lib\site-packages\django\core\management\__init__.py",
> line 382, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\lib\site-packages\django\core\management\base.py", line
> 196, in run_from_argv
> self.execute(*args, **options.__dict__) File "C:\Python27\lib\site-packages\django\core\management\base.py", line
> 232, in execute
> output = self.handle(*args, **options) File "C:\Python27\lib\site-packages\django\core\management\base.py", line
> 371, in handle
> return self.handle_noargs(**options) File "C:\Python27\lib\site-packages\django\core\management\commands\syncdb.py",
> line 57, in handle_noargs
> cursor = connection.cursor() File "C:\Python27\lib\site-packages\django\db\backends\dummy\base.py", line
> 15, in complain
> raise ImproperlyConfigured("settings.DATABASES is improperly configured. " django.core.exceptions.ImproperlyConfigured:
> settings.DATABASES is improperly configured. Please supply the ENGINE
> value. Check settings documentation for more details.
【问题讨论】:
-
您遇到了什么错误?你在哪里指定应该使用什么数据库?因为在您的 pgadmin 屏幕中,我只看到您不应该使用的 postgres 数据库,它被服务器用于组织目的。
-
另外,使用用户 postgres(也就是服务器的超级用户)与数据库进行交互可以进行快速测试,但在实际应用中不应该这样做。
-
@fvu 谢谢你的回答!我从 django 框架发布了我的错误消息。它说ENGINE值不正确,为什么?目前我正在使用屏幕截图中的 django db。提前谢谢!!!
-
你可以使用不同的客户端(例如,
psql)连接到 django 数据库吗? -
BTW
HOST在 Windows 上应设置为localhost或127.0.0.1,因为空字符串表示 UNIX 套接字连接,它在 Windows 上可用。但这不是你现在的问题。
标签: python django configuration psycopg2