【问题标题】:Using postgresql for Django under win7?win7下Django使用postgresql?
【发布时间】: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 上应设置为 localhost127.0.0.1,因为空字符串表示 UNIX 套接字连接,它在 Windows 上可用。但这不是你现在的问题。

标签: python django configuration psycopg2


【解决方案1】:

这是一个老问题,但我正在为未来的访问者添加一个答案。您似乎有几个错误:

  1. 如果您已经安装了 psycopg2,则应将 ENGINE 名称更改为 django.db.backends.postgresql_psycopg2

  2. 在您的设置中,您将数据库NAME 指定为django,但在您的pgAdmin 屏幕截图中可以看出您没有这样的数据库。使用 pgAdmin 创建一个名为 django 的数据库。

那么正确的设置应该是:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

【讨论】:

    猜你喜欢
    • 2012-10-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多