Django連接MySQL出錯(cuò)
錯(cuò)誤一:No module named 'MySQLdb'
原因:python3連接MySQL不能再使用mysqldb,取而代之的是pymysql祖搓。
解決方法:在python的MySQL包中狱意,即路徑:C:\Users\adong\AppData\Local\Programs\Python\Python36\Lib\site-packages\Django-2.0.3-py3.6.egg\django\db\backends\mysql
下的init.py文件中加入:
import pymysql
pymysql.install_as_MySQLdb()
錯(cuò)誤二:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11.None
原因:在解決了錯(cuò)誤一以后出現(xiàn)了此錯(cuò)誤。
解決方法:在python的MySQL包中拯欧,即路徑:項(xiàng)目路徑\venu\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)
謹(jǐn)以此篇獻(xiàn)給DJANGO學(xué)習(xí)過(guò)程中遇到的問(wèn)題
一、Django數(shù)據(jù)同步過(guò)程中遇到的問(wèn)題:
1镐作、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.
解決辦法:C:\Python37\Lib\site-packages\django\db\backends\mysql(python安裝目錄)打開base.py藏姐,注釋掉以下內(nèi)容:
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.version)
2、File "C:\Python37\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'
解決辦法:打開此文件把146行的decode修改為encode