报错如下:
File "/usr/local/python3/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
MySQLdb 只适用于python2.x,。在python3.x的替代品是: import pymysql
解决办法:
base.py 文件同目录下的__init__.py文件新增如下两行:
vi /usr/local/python3/lib/python3.4/site-packages/django/db/backends/mysql/__init__.py
import pymysql
pymysql.install_as_MySQLdb()
如果还报如下错误:
AttributeError: module 'pymysql' has no attribute 'install_as_MySQLdb'
解决方法:
pip uninstall PyMySQL3
pip install -U --force-reinstall pymysql