settings.DATABASES配置不正确。请提供NAME值

时间:2015-04-23 01:26:17

标签: python django heroku

我知道之前有人问过类似的问题。但这完全取决于发动机的价值。是否有人知道如何使用NAME值解决此错误?我部署到heroku,一切正常。但是,在本地,它给了我这个错误 这是追溯:

Traceback:
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/qiaoweiliu/Google Drive/heroku/luxingnan/views.py" in home
  17.         return render(request,'luxingnan/home.html',{'auth_form':auth_form, 'user_form':user_form,'cars':cars,'next_url': '/',})
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/shortcuts.py" in render
  67.             template_name, context, request=request, using=using)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  99.         return template.render(context, request)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/backends/django.py" in render
  74.         return self.template.render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/base.py" in render
  209.                     return self._render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  328.             if match:
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/models/query.py" in __nonzero__
  170.         return type(self).__bool__(self)
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/models/query.py" in __bool__
  166.         self._fetch_all()
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/models/query.py" in _fetch_all
  965.             self._result_cache = list(self.iterator())
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  238.         results = compiler.execute_sql()
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  827.         cursor = self.connection.cursor()
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/backends/base/base.py" in cursor
  162.             cursor = self.make_debug_cursor(self._cursor())
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/backends/base/base.py" in _cursor
  135.         self.ensure_connection()
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/backends/base/base.py" in ensure_connection
  130.                 self.connect()
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/backends/base/base.py" in connect
  118.         conn_params = self.get_connection_params()
File "/Users/qiaoweiliu/.virtualenvs/heroku/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py" in get_connection_params
  154.                 "settings.DATABASES is improperly configured. "

Exception Type: ImproperlyConfigured at /
Exception Value: settings.DATABASES is improperly configured. Please supply the NAME value.

这是我的setting.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

DATABASES['default'] =  dj_database_url.config()

DATABASES['default']['ENGINE'] = 'django_postgrespool'

2 个答案:

答案 0 :(得分:3)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

就够了。如果您想使用django_postgrespool,可以在上面进行编辑。

你的这一行:

DATABASES['default'] =  dj_database_url.config()

只需覆盖上述标准DATABASE设置。

答案 1 :(得分:3)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

import dj_database_url

db_config = dj_database_url.config()
if db_config:
    DATABASES['default'] =  db_config