Intellipaat Back

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

I'm using windows 10 command line for a django project using python34. However, I am facing difficulties with the SQL.

What I have installed is mysqlclient by using pip install mysqlclient==1.3.5 and located the file to make sure that I was not delusional. Thenafter then ran python manage.py migrate to migrate the tables to the SQL database (I am using phpmyadmin). However when the command returned with:

File "C:\Users\user\env\lib\site-packages\django\db\backends\mysql\base.py", line 30, in <module>
    'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?

I am aware that the questions like these already exist, but not one solution seems to have made any impact on the attempts. Thank you in advance. 

3 Answers

0 votes
by (12.7k points)

Execute the below code in cmd:

pip install pymysql

Then, you can edit __init__.py in your project origin dir (take the same as settings.py).

Add the following:

import pymysql

pymysql.install_as_MySQLdb()

 Interested in SQL ? Check out this SQL Certification by Intellipaat.

For more information visit :

Interested to learn more about Python? Come & join our Python course

0 votes
by (37.3k points)

The error message you received tells that Django is unable to load the MYSQL database module, this module comes from the package of mysqlclient. This usually happens when the package is not properly installed. To resolve it: 

  1. Install the package: 

Command: pip install mysqlclient 

        2. Verify Installation: 

Command: import MySQLdb 

0 votes
by (1.9k points)

I was also having a tough time with the "Error loading MYSQL dB module" it was so frustrating here is how i managed to fix it:

  • Check the virtual environment to ensure that MySQL-client was installed correctly or not
  • Switch to MySQL-connector-python (pip install MySQL-connector-python)
  • update the settings.py file to use the new connector
  • Post that, I tried running the migrations again with (python manage.py migrate)

lastly i double-checked that MySQL was properly installed and running on my system and i could access it through phpMyAdmin

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...