pymysql可能出现的版本不匹配问题
第一个问题
File "D:\virtualenv\wx\lib\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.
解决方案
根据提示信息进入源 码注销这两行,然后在运行
# if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
第二个问题
"D:\virtualenv\luffy\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
解决方案
再根据提示信息进入源码
# 在query = query.decode(errors='replace')解码这行上面,添加一行编码:
query = query.encode('utf8')
第三个问题
同时使用python3 与 Django出现的连接数据库问题
因为python3连接数据库使用 pymysql 库,而Django连接数据库使用 MySQLdb 库,所以在安装pymysql之后,Django调用会出现以下错误
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
解决方案
在项目根目录的__init__.py文件中加入以下代码即可
import pymysql
pymysql.install_as_MySQLdb()
**