3

Am Trying to connect to my mysql db from django app. I get the below error during migration:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module. Did you install mysqlclient?

I've already installed mysqlclient as below:

Requirement already satisfied: mysqlclient in /usr/local/lib/python3.7/site-packages (1.4.2.post1)

I've also tried with pymysql and adding below code to ini.py file:

import pymysql
pymysql.install_as_MySQLdb()

Gives me some other errors. What could be wrong?

Python 3.7 , mysql 5.7 and Django 2.2 are my setup versions.

7
  • 2
    Are you using the same environment for running django as you installed the MySQL client in? Commented Aug 8, 2019 at 8:49
  • What do you mean? Everything is on localhost Commented Aug 8, 2019 at 8:52
  • you need to check any virtual environment installed or not for your project. activate it and try to migrate. for activation in linux:- source envname/bin/activate Commented Aug 8, 2019 at 8:59
  • @PavanKumarTS Yes i've also tried through virtualenv and i get the same error Commented Aug 8, 2019 at 9:00
  • check with pip freeze Commented Aug 8, 2019 at 9:02

3 Answers 3

17

I had the same issue. Running the below command fixed it for me.

pip install --force-reinstall --ignore-installed --no-binary :all: mysqlclient

Sign up to request clarification or add additional context in comments.

Comments

0

I had the same issue. The thing that worked for me is the following:

https://stackoverflow.com/a/54521244/12497648,

except when I did brew install mysql-client I got the message Warning: mysql-client 5.7.23_1 is already installed and up-to-date To reinstall 5.7.23_1, run "brew reinstall mysql-client" so I ran brew reinstall mysql-client after which I continued with the instructions from the link above (export PATH... etc.)

(also don't forget to do the pip wheel mysqlclient / pip install mysqlclient)

Comments

0

If the error includes a Reason: image not found error, then it can be solved with symlinks like this:

Library not loaded: @rpath/libmysqlclient.21.dylib Reason: image not found Django migrate error using mysqlclient DB driver and MySQL 8 with macOS

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.