美文网首页
mysqlclient 1.3.13 or newer is r

mysqlclient 1.3.13 or newer is r

作者: 山高路远_海深不蓝 | 来源:发表于2019-07-29 12:24 被阅读0次

    环境说明

    • 阿里云CentOs7
    • msyql8.0
    • django2.2

    两台服务器,一台放数据库,一台部署应用,在执行数据库初始化的时候报错

    解决办法

    • 安装mysqlclient

    pip install pymysql

    • 修改项目目录下的 __init__.py(projrct/project/__init__.py)
    import pymysql
    pymysql.install_as_MySQLdb()
    
    • 修改源码文件

    根据错误提示找到base.py, ....django/db/backends/mysql/base.py

    # 注释掉下面两行,一般在35-36行
    if version < (1, 3, 3):
         raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)
    

    继续报错: AttributeError: ‘str’ object has no attribute ‘decode’

    根据错误提示找到operations.py

    # 修改decode为encode
    if query is not None:
        query = query.decode(errors='replace')
    return query
    

    重启apache

    systemctl restart httpd

    相关文章

      网友评论

          本文标题:mysqlclient 1.3.13 or newer is r

          本文链接:https://www.haomeiwen.com/subject/clxbrctx.html