【发布时间】:2012-09-03 20:03:23
【问题描述】:
我正在浏览 Django Book 并在尝试执行“cursor = connection.cursor()”命令来测试数据库配置时被卡住了。我是一个完全的菜鸟,但我确实花了几个小时试图找出问题 - 无济于事。 (很抱歉下面的终端输出显示混乱 - 所以不允许新用户发布图片)。
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.db import connection
>>> cursor = connection.cursor()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
>>> from django.conf import settings
>>> settings.DATABASES
{'default': {'ENGINE': 'django.db.backends.dummy', 'TEST_MIRROR': None, 'NAME': '', 'TEST_CHARSET': None, 'TIME_ZONE': 'UTC', 'TEST_COLLATION': None, 'OPTIONS': {}, 'HOST': '', 'USER': '', 'TEST_NAME': None, 'PASSWORD': '', 'PORT': ''}}
>>>
我进行了 settings.DATABASE 检查,结果与我保存在 settings.py 文件中的结果不同 - 这是问题的来源吗?
我看到这里有几个关于这个问题的类似问题 - 但他们都没有为我解决问题。
这是我从 settings.py 设置的数据库:
***
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydb', # Or path to database file if using sqlite3.
'USER': 'paul', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
***
感谢您的帮助。
【问题讨论】:
-
您有一个 MySQL 数据库并正在运行吗?这是您在设置中指定的内容。
-
是 - MySQL 服务器实例正在运行。我刚刚尝试使用“sqllite3”而不是 MySQL,它似乎正在工作。但如果我能解决这个问题,我想继续使用 MySQL。
-
所以数据库没有密码吧?另外,尝试使用设置文件显式运行:
python manage.py shell --settings=myproject.settings(或类似文件) -
我现在更改的某些设置阻止我进入“python manage.py shell”解释器,将我的输出发布在另一个问题中:stackoverflow.com/questions/12254232/…
标签: python django django-settings