2011-05-21 101 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': '', 
    } 
}