Django開發,由sqlite3切換爲mysql
已經僞裝過了, 遷移時,報錯:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
解決辦法:
- 將Django降低到2.14以下即可。(沒試過)
II、升級mysql客戶端版本至更高。(沒試過)
III、按照以下步驟修改代碼。 (親測有效)
按圖找到你Django目錄下的base.py文件
註釋掉下面2句:
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.version)
然後再進行數據庫遷移操作。
如果還有問題,比如出現了以下問題:
File "D:\Program Files\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'
那就打開上圖中的operations.py文件,146行中的decode改爲encode即可。
然後再次遷移,成功!