1

我目前正在玩 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.
4

1 回答 1

0

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

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

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

正确的设置将是:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'django',
        'USER': 'postgres',
        'PASSWORD': 'postgres',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}
于 2015-02-15T13:34:00.410 回答