1

I am currently working on Ubuntu 14.10/Python/Django/MySQL and encountering the following error when I try to run:

$python manage.py makemigrations polls

or

$python manage.py migrate polls

I have also tried syncdb The error is:

(Aaronpythonenv)aaron@aaron-N550JK:~/mysite$ python manage.py makemigrations polls Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 338, in execute_from_command_line utility.execute() File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 312, in execute django.setup() File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/init.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/registry.py", line 108, in populate app_config.import_models(all_models) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/auth/models.py", line 41, in class Permission(models.Model): File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 139, in new new_class.add_to_class('_meta', Options(meta, **kwargs)) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 324, in add_to_class value.contribute_to_class(cls, name) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/options.py", line 250, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/init.py", line 36, in getattr return getattr(connections[DEFAULT_DB_ALIAS], item) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 240, in getitem backend = load_backend(db['ENGINE']) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module import(name) File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/mysql/base.py", line 27, in raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I have used PIP to install mysql-python to my environment which I recieved another error. I then used sudo apt-get command to install correct the error PIP brought up.

massive thank you in advance please let me know if I need to add anything else.

3
  • Be careful, if you are working in a virtualenv, apt-get will not install the library in it. Check if MySQLdb is installed in your virtualenv using the pip freeze command Commented Apr 14, 2015 at 15:46
  • @karec thank you, I have tried this. when i search through Virtualenv (and my env folder) I already have the version satisfied, everything worked fine before I inserted classes, but I am following the Django guide and coming up short Commented Apr 14, 2015 at 16:06
  • Can you update your post with the pip freeze output and your Databases section in the settings.py file ? i will take a look Commented Apr 14, 2015 at 16:16

2 Answers 2

5

I faced somewhat similar problem. Try these steps:

1). Upgrade pip to the latest version.

sudo pip install pip --upgrade

2). Build the dependencies for python-mysqldb libraries:

sudo apt-get build-dep python-mysqldb

3). Install the Python MySQL libraries:

sudo pip install MySQL-python
Sign up to request clarification or add additional context in comments.

Comments

3

I think it means there is no module named mysqldb. You just need to setup the mysqldb module. For example if you use the ubuntu, you just need to run this command:

sudo apt-get install python-mysqldb

and then you problem will be fixed!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.