問題1
執(zhí)行makemigrations命令時提示:django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.2.
詳細如下
File "C:\Python37\lib\site-packages\django\db\backends\mysql\base.py", line 36, in <module>
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.2.
解決方法:
- 方法一:按要求安裝mysqlclient 1.3.13或以上版本摇零。
- 方法二: 找到
C:\Python37\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'
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'
解決方法:
- 找到
django\db\backends\mysql\operations.py
文件下的last_executed_query方法,如下
old
def last_executed_query(self, cursor, sql, params):
# With MySQLdb, cursor objects have an (undocumented) "_executed"
# attribute where the exact query sent to the database is saved.
# See MySQLdb/cursors.py in the source distribution.
query = getattr(cursor, '_executed', None)
if query is not None:
query = query.decode(errors='replace')
return query
- 修改last_executed_query方法
new
from django.utils.encoding import force_str
def last_executed_query(self, cursor, sql, params):
# With MySQLdb, cursor objects have an (undocumented) "_executed"
# attribute where the exact query sent to the database is saved.
# See MySQLdb/cursors.py in the source distribution.
# MySQLdb returns string, PyMySQL bytes.
return force_str(getattr(cursor, '_executed', None), errors='replace')
- 然后再執(zhí)行makemigrations命令就可以了