django执行python manage.py migrate时报错问题
执行如下命令时报错(迁移数据库和表结构):
python manage.py makemigrations python manage.py migrate
执行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 version for the right syntax to use near '(6) NOT NULL)' at line 1"))
环境信息:
python3.7.0 + django2.2.12 + mysql5.5.62
报错原因:
Django 2.1.x 以后要求MySQL 5.6或更高。它通过将DateTimeField映射到datetime(6)打破了兼容性,根本原因就是不兼容。
解决办法:
1、安装更高版本的Mysql数据库。
2、在settings.py文件最顶部增加如下代码:
from django.db.backends.mysql.base import DatabaseWrapperDatabaseWrapper.data_types['DateTimeField'] = 'datetime' # fix for MySQL 5.5
重新执行python manage.py migrate命令。
转载解决办法的链接:
Django >python manage.py migrate报错:(1064, "You have an error in your SQL syntax - 灰信网(软件开发博客聚合)