I am going through the Django Book and got really stuck when trying to execute the ‘cursor = connection.cursor()’ command to test the database configuration. I am a complete noob but I did spend several hours trying to identify the problem – to no avail. (sorry for the messy display of terminal output below – SO doesn’t let new users post images).
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': ''}}
>>>
I did the settings.DATABASE check and the result comes out different from what I’ve saved in my settings.py file – is that the source of the porblem?
I saw that there are several similar questions about this issue here – but none of them resolved the problem for me.
Here’s my database set up from 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.
}
}
***
Thank you for your help.
I suspect it might be because the book is outdated (Django evolves fairly quickly and many backwards-incompatible changes have taken place since the book was written). See note on the front page of The Django Book:
So it’s probably not your fault that this error is showing up! 🙂
If you haven’t already done so, I recommend you go through the official Django tutorial (link available via the Django home page) and read through the docs. The tutorial and docs are kept quite up to date. However, just be careful you’re looking at the documentation for the Django version you have installed (the documentation may vary for each Django version released). You can switch documentation versions via the switcher on the bottom-right-hand-side of the website (
).
The Django Book still has value though as it reveals a lot about the philosophy behind Django — but just be aware the code provided might not work with the current Django version.