django 连接数据库的问题

错误一:No module named 'MySQLdb'

原因:python3连接MySQL不能再使用mysqldb,取而代之的是pymysql。

解决方法:在python的MySQL包中,即路径:C:\Python3\Lib\site-packages\django\db\backends\mysql下的__init__.py文件中加入:

import pymysql

pymysql.install_as_MySQLdb()

错误二:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.9.11.None

原因:在解决了错误一以后出现了此错误。

解决方法:在python的MySQL包中,即路径:C:\Python3\Lib\site-packages\django\db\backends\mysql下的 base.py 文件中,注释掉一下两行代码:

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

posted @ 2019-08-17 10:49  屌丝的IT  阅读(127)  评论(0)    收藏  举报