2

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.

Amira Bedhiafi
  • 8,088
  • 6
  • 24
  • 60
Makamu Evans
  • 491
  • 1
  • 10
  • 25

3 Answers3

14

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

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

shawshank718
  • 169
  • 1
  • 6
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)

lndh
  • 1
  • 3
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

M3RS
  • 6,720
  • 6
  • 37
  • 47