Django踩坑之django.core.exceptions.ImproperlyConfigured mysqlclient 1.3.13 or newer is required; you have 0.9.3.

安装Django3后不想折腾mysqlclient那堆库文件,直接装了pymysql替代mysqlclient,报错:django.core.exceptions.ImproperlyConfigured mysqlclient 1.3.13 or newer is required; you have 0.9.3.。实际上pymysql版本号是 0.9.3,却明目张胆篡改version_info欺骗Django😂。这样一来就简单了,patch一下这个属性就行了嘛,# 在与 settings.py 同级目录下的 init.py 中引入模块和进行配置, 修改__init__.py,多插入一行代码:

import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()

setting.py中设置:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'NAME':'mysql',
        'HOST':'localhost',
        'USER':'root',
        'PASSWORD':'',
        'HOST':'127.0.0.1'
    }
}

参考博客:https://yuntianti.com/posts/fix-django3-mysqlclient-import-error/

posted @ 2020-06-01 12:45  JohnYang819  阅读(537)  评论(0编辑  收藏  举报