在python3环境下,使用Django链接mysql,在settings.py中配置好各个设置项后执行python manage.py migrate
,出现了以下错误:
1.
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb',
主要是python2使用mysqldb,python3使用pymysql,所以在使用pymysql时就有问题了,解决:
在init.py中写
import pymysql
pymysql.install_as_MySQLdb()
重新执行python manage.py migrate
,又有错:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required;
you have 0.9.3.
虽然版本最新,但还是报错,解决:在异常传播途径的最后一条点进去base.py
,注释掉35,36行,即
34 version = Database.version_info
35 #if version < (1, 3, 13):
36 # raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.'