在win7下使用postgresql for Django?

时间:2013-02-02 18:51:33

标签: python django configuration psycopg2

我目前正在玩django并希望用作我的数据库postgresql:

enter image description here

这些是我在设置文件中的配置:

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.

1 个答案:

答案 0 :(得分:0)

这是一个老问题,但我为未来的访客添加了一个答案。你似乎有几个错误:

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

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

  3. 然后正确设置:

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