• mac + python3.8 + django3.0.8 + mysql 遇到数据库连接包问题


    到达数据库迁移的时候, 出现了错误

    django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
    Did you install mysqlclient?

    安装pymysql包

    pip install pymysql

    然后在与想settings.py 同一文件夹的_init_.py中增加

    import pymysql
    
    pymysql.install_as_MySQLdb()

    增加完成了之后又出现了错误

    File "/Users/mac/.virtualenvs/django-sPhxDNwQ/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 36, in <module>
        raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
    django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
        

    方案是去Django的包中改代码

    路径是:

    /Users/mac/.virtualenvs/django-sPhxDNwQ/lib/python3.7/site-packages/django/db/backends/mysql/base.py

    我的是虚拟环境,个人找自己mysql的安装包文件base.py

    把这行

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

    改成这样, 全部注释:

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

    然后在改另一个文件

    路径是: /Users/mac/.virtualenvs/django-sPhxDNwQ/lib/python3.7/site-packages/django/db/backends/mysql/operations.py

    把这行

    query = query.decode(errors='replace')

    改成

    query = query.encode(errors='replace')
     
  • 相关阅读:
    Python之struct模块浅谈
    看头发知健康
    ZeroMQ:云计算时代最好的通讯库
    粗盐热敷疗法经验汇总
    百度2011校招笔试算法题一
    new/delete 和malloc/free 的区别一般汇总
    Trie字典树
    百度2012校招笔试题之全排列与组合
    百度2011校招笔试算法题二
    执行程序的内存分布总结
  • 原文地址:https://www.cnblogs.com/shenZS/p/13334902.html
Copyright © 2020-2023  润新知