Django
最近在使用Django迁移数据库时,遇到了一个问题。
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
下面我们就来解决它,因为Django版本不一样,少许有些不一样,先说明下环境
- Python:3.7.3
- Django:3.0.1
- PyMySQL:0.9.3
在执行python manage.py mirgate
迁移数据库时,会报如下错误
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
网上查找了一些资料,基本上可以定义为django内部的一个版本限制在作怪
对就是它:
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
根据你Django的目录找到base.py文件(在site packages里可以找到django目录),注释掉这两行代码!!
==例如:… /lib/python3.7/site-packages/django/db/backends/mysql ==
在这里就大功告成,妥妥的!
重新执行python manage.py migrate
迁移数据库
写在后面的话:因为我用的是Django3.0.1版本,没有出现网上其他人出现的后续问题。
File "/usr/local/bin/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'
根据提示打开上图位置所说位置将代码中的decode改为encode就可以了。
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.encode(errors='replace')
return query