Django failed to use MySQL under mac



python makemigrations

Will report an error

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

After that, even if mysqlclient is installed, an error will still be reported


pip install pymysql

Under the project directory__ init__ . py plus

import pymysql  

Then in the python installation environment, Python 3.6/site-packages/django/db/backends/mysql/ Comment out the if statement as follows:

version = Database.version_info  
# if version < (1, 3, 13):  
#    raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)

Run Python again Make migrations.
If the error is still reported

AttributeError: ‘str’ object has no attribute ‘decode’


#Find File, change decode to encode
if query is not None:
    query = query.decode(errors='replace')
return query
#Change to
if query is not None:
    query = query.encode(errors='replace')
return query

Recommended Today

Heavy! With the release of JDK 17, Oracle announced that JDK 17 is officially free..

Previous edition:JDK 16 was officially released and 17 new features were released at one time… No! JDK 17 officially released + free It’s awesome. JDK 16 has just been released for half a year (2021 / 03 / 16), and JDK 17 arrives as scheduled (2021 / 09 / 14). At this time, it’s awesome. […]