Liondancer
Liondancer

Reputation: 16469

Django book Chapter 5 Database Engine setting

I'm pretty sure I followed the procedures for this tutorial accurately but I'm still getting errors =/

Currently, my settings.py DATABASES looks like this

DATABASES = {
    'default': {
        'ENGINE': 'mysql',  # Add 'postgresql_psycopg2', 'mysql','sqlite3' or 'oracle'.      
        'NAME': 'mydb',     # Or path to database file if using sqlite3.
        'USER': 'user',     # Not used with sqlite3.
        'PASSWORD': 'pwd',  # 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.
    }
}

The tutorial tells me to have 'mysql' in ENGINE. However when I try to use the command 'python manage.py shell' I get this error

django.core.exceptions.ImproperlyConfigured: 'mysql' isn't an available database backend.
Try using django.db.backends.mysql instead.
Error was: No module named mysql.base

This is why I have django.db.backends.mysql next to ENGINE.

After these settings, the tutorial tells me to type in these commands

'python manage.py shell'     <--- works fine

from django.db import connection      <--- works fine

cursor = connection.cursor()          <--- uh oh

After running the cursor command, I get this error

http://pastebin.com/8MtYq7rg

Not really sure what this means =/

When I try to run my server with python manage.py runserver I get this error. Not sure what this means either but the last error seems to be the same.

http://pastebin.com/91U3dz73

Also I looked up online to use python manage.py dbshell to test my DB access and this is the message I get.

Error: You appear not to have the 'mysql' program installed or on your path.

I posted this problem on reddit to see if I could get any extra help. I hope some of this information provides extra help to this problem.

  1. Type MySQL in a shell and see the result
  2. Post how you installed MySQL. Did you make a table for Django to use already?
  3. What OS are you using?

    1. Nothing happens when I type in MySQL in shell. When I type in the command 'python manage.py shell' then MySQL. I get an error "NameError: name 'MySQL' is not defined". When i type MySQL in terminal, it says MySQL: command not found

    2. How I installed MySQL was that I downloaded the file and then extracted where the tar file is located. Next I put the extracted folder into /home/Development directory. All my code is stored in /home/Development/djcode/mysite/mysite/

    3. I am using Ubuntu

******UPDATE*UPDATE***************

So I believe that I was getting my error due to the fact that I didn't have MySQL installed/downloaded. What I had was MySQL-Python which isnt the same thing... But anyways, I downloaded/installed MySQL and ran python shell with 'python manage.py shell' then 'from django.db import connection' and then 'cursor = connection.cursor()'

However, I get the following error

OperationalError: (1045, "Access denied for user 'bradford'@'localhost' (using password: YES)")

Not sure what to do at this point =/

Upvotes: 2

Views: 2428

Answers (3)

cwallenpoole
cwallenpoole

Reputation: 82028

This is response to your update. That is a MySQL error. MySQL sets up restrictions on how and where a user is able to access the database. You can find that documentation here, but the tl;dr is that you need to make sure the user exists, the password is correct, and that you are connecting from the correct domain.

Upvotes: 0

Raunak Agarwal
Raunak Agarwal

Reputation: 7228

I guess you are missing Python MySQLDB

Upvotes: 3

Rag Sagar
Rag Sagar

Reputation: 2374

Look here https://docs.djangoproject.com/en/dev/ref/settings/#engine

You should use

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        ....
    }
}

Upvotes: 1

Related Questions