Download and install PyMySQL, And in the project file with the same name as the project __init__.py Add the following code to . If your image source has not been changed , You can refer to Python Switch pip Mirror source , After change , Download speed will be much faster
# install pymysql
pip install pymysql
# __init__.py
import pymysql
pymysql.install_as_MySQLdb()
Method 1 :
Just lower django The version of .
# Access terminal , Sometimes according to pip On the version , Need to use pip3
# Input pip uninstall django, Remove django2.2
C:\Users\Administrator>pip uninstall django
# Input pip install django==2.1.4, Install version of django
C:\Users\Administrator>pip install django==2.1.4
If you can't uninstall , Direct installation is also possible
Method 2 :
Continue to use the current version (django=2.2)
# find python In the environment django package , And then into db Under the backends Under the mysql Folder
cd /home/wls/.local/lib/python3.6/site-packages/django/db/backends/mysql
Don't know django What about the installation directory of ? Continue to read down , Methods are presented immediately
# ubuntu System or windows Under the system
# Access terminal , Then enter python, Enter the following command
[email protected]:~$ python3
Python 3.6.8 (default, Jan 14 2019, 11:02:34)
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.__path__)
['/home/wls/.local/lib/python3.6/site-packages/django']
# windows Enter the terminal under the system
C:\Users\Administrator>pip show django
......
Location: f:\python\lib\site-packages
Both of the above methods can be found django Installation path for , Is it exciting
On the basis of step 2, method 2 , find base.py file , And use vi or vim open base.py file , Comment the relevant code , As shown in the figure below :
# notes base.py The following part of the code in the file
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
It's finally over , Be accomplished , Then there will be errors when running the project , At this time, a cool song should be played , More suitable for the current atmosphere
Error message :
AttributeError: 'str' object has no attribute 'decode'
It is also found in the directory in the previous step operations.py Document and use vi or vim open operations.py file , Comment the relevant code :
# notes operations.py The following part of the code in the file ( This file is a bit long , Take your time ), take decode It is amended as follows encode
# ubuntu in vim Find with shortcut keys : ?decode
if query is not None:
query = query.decode(errors='replace')
return query
# It is amended as follows
if query is not None:
query = query.encode(errors='replace')
return query
And that's it
Articles you may be interested in