2011-05-21 240 views
2

在尝试运行./manage.py runserver或shell或任何其他命令时,出现错误:您必须定义一个“默认”数据库。django manage.py raise错误地配置错误

我在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 
+0

您是否检查过此内容:http://docs.djangoproject.com/en/1.3/ref/settings/#databases? “DATABASES设置必须配置默认数据库; ...” – arie 2011-05-21 14:39:31

回答

9

DATABASE_NAME被废弃了,因为Django的1.2,所以如果你使用较新的版本,您应该使用new way of defining databases

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

啊。我现在看到它。我正在使用http://github.com/ryanmark/django-project-templates。不幸的是,Paste安装的设置文件使用了不推荐的版本,而requirements.txt文件安装了django-trunk。 – wmfox3 2011-05-21 17:04:22

+0

看来,在“简单项目”中,他们确实使用新版本:https://github.com/ryanmark/django-project-templates/blob/master/src/django_project_templates/templates/simple_project/config/settings.py_tmpl,但在'django项目'中他们没有。你可以很好,并在https://github.com/garethr/django-project-templates/issues上报告问题,甚至更好,并叉他们,并修复:) – 2011-05-21 18:27:26

4

定义数据库名是settings.py

DATABASE 下面是一个例子

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