Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (6.1k points)

The problem I'm facing while trying to connect to database for MySQL. 

Traceback (most recent call last):
 File "", line 10, in <module>
 File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/", line 453, in execute_from_command_line
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/", line 392, in execute
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/", line 77, in load_command_class
module = import_module('' % (app_name, name))
File "/home/arundhati/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/", line 35, in import_module
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/commands/", line 8, in <module>
from import custom_sql_for_model, emit_post_sync_signal
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/core/management/", line 9, in <module>
from django.db import models
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/", line 27, in load_backend
return import_module('.base', backend_name)
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/utils/", line 35, in import_module
File "/home/ar/Desktop/test/testprac/local/lib/python2.7/site-packages/django/db/backends/mysql/", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I have also given below the database settings that I have used :

    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'ar_test_db',                      # Or path to database file if using 
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or   '' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.

1 Answer

0 votes
by (12.7k points)
edited by

It looks such as you do not have the python MySQL package installed, try:

pip install mysql-python

or if you aren't using a virtual environment (on *nix hosts), then try:

sudo pip install mysql-python

I hope I could be helpful.

If you want to learn more about SQL, Check out this SQL Certification by Intellipaat.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers


104k users

Browse Categories