我正在浏览 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.
}
}
***
感谢您的帮助。