django manage.py提出错误配置错误

时间:2011-05-21 14:34:18

标签: django

在尝试运行./manage.py runserver或shell或任何其他命令时,我收到错误:您必须定义一个'默认'数据库。

我在virtualenv中运行它,settings.py包括DATABASE_NAME,以及主机,端口和引擎。 django期望定义默认数据库在哪里?

这是追溯:

(env)fox-ser01:common wmfox3$ ./manage.py shell
Traceback (most recent call last):
  File "./manage.py", line 31, in <module>
execute_manager(settings)
  File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
  File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
  File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
  File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
  File "/Users/wmfox3/Sites/photo_project/env/src/django/django/db/__init__.py", line 12, in <module>
raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)
django.core.exceptions.ImproperlyConfigured: You must define a 'default' database

3 个答案:

答案 0 :(得分:9)

自django 1.2以来,DATABASE_NAME已弃用,因此如果您使用的是较新版本,则应使用new way of defining databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'mydatabase'
    }
}

答案 1 :(得分:4)

定义db name是settings.py

DATABASE 以下是一个例子

DATABASES = {
    'default': {
        'ENGINE': 'mysql',
        'NAME': 'xyz', # db name
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': '',
        'PORT': '',
    }
}

答案 2 :(得分:0)