Django和venv:settings.DATABASES配置不正确。请提供ENGINE值

时间:2013-01-24 13:17:11

标签: django virtualenv

当我运行python manage.py syncdb时会发生这种情况。当我运行python manage.py syncdb --mysite.settings时也会发生这种情况。不知道从哪里开始:django无法识别我的设置文件,我不知道为什么或如何纠正它。

python ../manage.py syncdb
Traceback (most recent call last):
  File "../manage.py", line 9, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ryan/Programming/OpenCV-2.4.2/msheroku/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/home/ryan/Programming/OpenCV-2.4.2/msheroku/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ryan/Programming/OpenCV-2.4.2/msheroku/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/ryan/Programming/OpenCV-2.4.2/msheroku/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/home/ryan/Programming/OpenCV-2.4.2/msheroku/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/home/ryan/Programming/OpenCV-2.4.2/msheroku/venv/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/home/ryan/Programming/OpenCV-2.4.2/msheroku/venv/local/lib/python2.7/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.

来自settings.py

DATABASES = { 
    'default': {
        'ENGINE': 'postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'xxx',                      # Or path to database file if using sqlite3.
        'USER': 'xxx',                      # Not used with sqlite3.
        'PASSWORD': 'xxx',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }   
}

我非常确信它没有找到合适的设置文件。

2 个答案:

答案 0 :(得分:4)

您好我假设您正在使用heroku测试您的应用并尝试连接到本地数据库?如果是这样,请务必删除这行代码:

# Parse database configuration from $DATABASE_URL
  import dj_database_url
  DATABASES['default'] =  dj_database_url.config()

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
  SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

当您要连接到另一台服务器上的数据库时添加它。

答案 1 :(得分:0)

正确的看起来像这样。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '',                      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

编辑:将主机更改为localhost以反映评论&amp; manage.py

根据您运行syncdb的方式

python manage.py syncdb --mysite.settings

确保您的manage.py文件具有指定的正确DJANGO_SETTINGS_MODULE

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

然后,您应该能够在没有--mysite.settings

的情况下运行syncdb
python manage.py syncdb