zoukankan      html  css  js  c++  java
  • 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')
     
  • 相关阅读:
    20150324--Mysql索引优化-02
    20150324--Mysql索引优化-01
    20150323--memcache-02
    20150323--memcache-01
    轮播效果/cursor
    事件监听和事件概念
    BOM与DOM操作
    for循环语句/命名函数
    数组/控制语句
    数据类型转换/正则表达式
  • 原文地址:https://www.cnblogs.com/shenZS/p/13334902.html
Copyright © 2011-2022 走看看