1

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.

Simeon Visser
  • 118,920
  • 18
  • 185
  • 180
entrepaul
  • 927
  • 3
  • 12
  • 23
  • Do you have a MySQL database up and running? That is what you have specified in your settings. – Simeon Visser Sep 03 '12 at 20:19
  • Yes - the MySQL server instance is running. I just tried using 'sqllite3' instead of MySQL and it seems to be working. But I would like to proceed with MySQL, if I can fix this issue. – entrepaul Sep 03 '12 at 20:23
  • 1
    So the database has no password right? Also, try running explicitly with the settings file: `python manage.py shell --settings=myproject.settings` (or similar) – Simeon Visser Sep 03 '12 at 20:26
  • Some setting that I changed now prevents me from getting into 'python manage.py shell' interpreter, posted my output in another question: http://stackoverflow.com/questions/12254232/django-1-4-1-error-loading-mysqldb-module-when-attempting-python-manage-py-shel – entrepaul Sep 03 '12 at 21:35

1 Answers1

3

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:

This book was originally published by Apress in 2009, and covered Django 1.0. Since then, it’s languished. We’re working on getting the book updated to cover Django 1.4, 1.5, and beyond.

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 (view screenshot).

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.

halex
  • 16,253
  • 5
  • 58
  • 67
stellarchariot
  • 2,872
  • 1
  • 19
  • 28