ubuntu下django连接mysql报错详解

China☆狼群 提交于 2019-12-09 19:16:35

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

  • 首先安装pymysql在pycharm中点击File Settings 在这里插入代码片 project Project Interpreter 点击右方加号,直接搜索pymysql然后左下角点击Install Package提示安装成功后关闭。
  • 然后在与想settings.py 同一文件夹的_init_.py中增加
    import pymysql pymysql.install_as_MySQLdb()
  • 之后在报错django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.说你的pymysql的版本是0.9.3, 同时需要mysqlclient是1.3.13。这个时候根据报错的内容去更改base.py文件。我的base.py文件目录在将下面这行
`if version < (1, 3, 13):
   raise ImproperlyConfigured(
       'mysqlclient 1.3.13 or newer is required; you have %s.'
       % Database.__version__
   )`

改成,也就是将if下面的语句进行注释

if version < (1, 3, 13):
   pass
   '''
   raise ImproperlyConfigured(
       'mysqlclient 1.3.13 or newer is required; you have %s.'
       % Database.__version__
   )
   '''
  • 然后在进行另外一个文件的更改operations.py文件
    目录在/usr/local/lib/python3.6/dist-packages/django/db/backends下面,然后将下面这句
query = query.decode(errors='replace')

改成

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

然后再次运行python manage.py runserver就可以了,完美解决!!!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!