gpt4 book ai didi

django manage.py 引发 ImproperlyConfigured 错误

转载 作者:行者123 更新时间:2023-12-02 18:14:31 26 4
gpt4 key购买 nike

在尝试运行 ./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

最佳答案

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

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

关于django manage.py 引发 ImproperlyConfigured 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6082390/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com