Solution 1
To use the PyMySQL module, just use pip install pymysql directly.
Reference article: https://www.cnblogs.com/wcwnina/p/8719482.html
Original content:
python3 does not support MySQLdb, you can use pymysql instead. cmd install pymysql: pip install pymysql. Add the following code to _init_.py in the project folder. import pymysql pymysql.install_as_MySQLdb() Then execute the database migration command in Terminal: python manage.py makemigrations python manage.py migrate
Solution 2
This article strongly recommends using method 2 to achieve. Because the pymysql module in method 1 is used, there may be some bugs that are difficult to solve due to module problems in the subsequent operation of the mysql database of the project.
The mysqlclient module is recommended here. It should be noted that python3 cannot directly use pip install mysqlclient to install mysqlclient, but Python2 can do this. So how does Python3 install the mysqlclient module correctly? Two pre-packages need to be installed here, as follows:
(1)sudo apt-get install python-dev libmysqlclient-dev # Debian / Ubuntu
(2)sudo apt-get install python3-dev # debian / Ubuntu
The installation statements in the above two steps are the installation commands on the Ubuntu system, Windows or CentOS system, and you can replace them according to the comparison.
After installing the above two libmysqlclient-dev and python3-dev prepackages, use pip install mysqlclient to successfully install on Python3.
Original link: https://github.com/PyMySQL/mysqlclient-python