代码运行环境说明:
Python:3.7.4
Django:2.2.6
PyMySQL:0.9.3
执行数据库迁移时输入命令:python manage.py makemigrations出现以下提示:
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
网上查资料发现解决方法有三种:
- 将你的Django降低到2.14以下;
- 升级的mysql客户端版本至更高 ;
- 按照以下步骤修改代码:
将base.py中
修改为:
继续输入命令:python manage.py migrate如果出现以下情况:
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中的
修改为:
继续执行命令:python manage.py migrate如果出现以下情况:
django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the django_migrations table ((1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server ver
sion for the right syntax to use near '(6) NOT NULL)' at line 1"))
这个是因为Django2.1不再支持MySQL5.5,必须5.6版本以上
解决办法:将MySQL升级