Django2.2链接mysql数据库出现django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is requ

在使用Django2.2开发的时候,想要使用mysql数据库,在settings.py文件中更改命令:python

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

}
}sql

再安装好pymysql,而后在__init__.py文件中添加:数据库

import pymysqldjango

pymysql.install_as_MySQLdb()ui

而后在models中建立好表类后,进行数据迁移时出现问题:spa

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

上网查一下解决方法,费了好大劲开发

解决方法:string

1.找到base.py文件,个人是在~/PycharmProject/myBlog/venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py

就是在你项目文件夹下的/venv/lib/python3.6/site-packages/django/db/backends/mysql/中

进去进行修改:

找到这段代码:version = Database.version_info

修改下面的if语句:添加pass,再注释掉,就像这个样子:

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

保存后,在进入同路径下的operations.py文件

query = query.decode(errors='replace')中的decode改成encode

保存

再次进行数据迁移,成功!能够成功链接到mysql。

相关文章
相关标签/搜索