Django開發遇到的幾個坑兒
1. django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11.None
解決方法:觀察錯誤信息,找到報錯文件: Lib\site-packages\django\db\backends\mysql\base.py
找到如下代碼,將其註釋。
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
2.AttributeError: ‘str’ object has no attribute ‘decode’
解決方法:觀察報錯信息,找到報錯文件Lib\site-packages\django\db\backends\mysql\operations.py
找到文件中的last_executed_query函數,將其中的如下代碼註釋:
if query is not None:
query = query.decode(errors='replace')
3. 執行 python manage.py migrate 報pymysql.err.InternalError: (1050, “Table ‘XXXX’ already exists”)
問題重現:用Django的ORM操作已有的數據庫表,導致同步到數據庫操作失敗。
解決方法:輸入指令python manage.py migrate --fake(假裝已經同步到數據庫了-_-)