Django2.2 mysql database connection appear django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11.None problem

When using Django2.2 development, I want to use the mysql database, change the command in settings.py file:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'python',
'USER': "root",
'PASSWORD': "yhr2323214310",
'HOST': '',
'PORT': ''

}
}

Then installed pymysql, then add in the __init__.py file:

import pymysql

pymysql.install_as_MySQLdb()

Then create a good table class models, make the problem occurs when data migration:

django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11.None

Check the Internet solutions, and with great effort

Solution:

1. Locate the file base.py, I was in ~ / PycharmProject / myBlog / venv / lib / python3.6 / site-packages / django / db / backends / mysql / base.py

It is /venv/lib/python3.6/site-packages/django/db/backends/mysql/ under your project folder

Go to modify:

Found this code: Version = Database.version_info

Modify the following if statement: Adding pass, and then comment out, like this:

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

After saving, entering operations.py files under the same path

The query = query.decode (errors = the 'replace') decode to encode

Storage

Data migration again, success! You can successfully connect to mysql.

 

Guess you like

Origin www.cnblogs.com/Horace-blogs/p/11357232.html