django无法同步mysql数据库 Error:1064
具体问题:新建django工程,使用django的manage.py的 migrate命令进行更改。
django.db.migrations.exceptions.MigrationSchemaMissing:
Unable to create the django_migrations table (
(,
"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"))
mysql5.(版本: 5.5.-CDB-2.0.-log)
django=='2.1'
pymysql=='0.9.2'
【原因分析】
测试:更换mysql服务器,使用mysql(版本: 5.7.17-log),其他django,pymysql版本不变。正常同步a.无错 b.直接查表,表结构正确
从测试结果推测原因可能是跟mysql版本有关,因此需要知道具体执行的sql语句
File tracking disabled
BEGIN;
--
-- Create model Permission
--
CREATE TABLE `auth_permission` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` varchar() NOT NULL, `content_type_id` integer NOT NULL, `codename` varchar() NOT NULL);
--
-- Create model Group
--
CREATE TABLE `auth_group` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` varchar() NOT NULL UNIQUE);
CREATE TABLE `auth_group_permissions` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `group_id` integer NOT NULL, `permission_id` integer NOT NULL);
--
-- Create model User
--
CREATE TABLE `auth_user` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `password` varchar() NOT NULL, `last_login` datetime() NOT NULL, `is_superuser` bool NOT NULL, `username` varchar() NOT NULL UNIQUE, `first_name` varchar() NOT NULL, `last_name` varchar() NOT NULL, `email` varchar() NOT NULL, `is_staff` bool NOT NULL, `is_active` bool NOT NULL, `date_joined` datetime() NOT NULL);
CREATE TABLE `auth_user_groups` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `user_id` integer NOT NULL, `group_id` integer NOT NULL);
CREATE TABLE `auth_user_user_permissions` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `user_id` integer NOT NULL, `permission_id` integer NOT NULL);
ALTER TABLE `auth_permission` ADD CONSTRAINT `auth_permission_content_type_id_2f476e4b_fk_django_co` FOREIGN KEY (`content_type_id`) REFERENCES `django_content_type` (`id`);
ALTER TABLE `auth_permission` ADD CONSTRAINT auth_permission_content_type_id_codename_01ab375a_uniq UNIQUE (`content_type_id`, `codename`);
ALTER TABLE `auth_group_permissions` ADD CONSTRAINT `auth_group_permissions_group_id_b120cbf9_fk_auth_group_id` FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`);
ALTER TABLE `auth_group_permissions` ADD CONSTRAINT `auth_group_permissio_permission_id_84c5c92e_fk_auth_perm` FOREIGN KEY (`permission_id`) REFERENCES `auth_permission` (`id`);
ALTER TABLE `auth_group_permissions` ADD CONSTRAINT auth_group_permissions_group_id_permission_id_0cd325b0_uniq UNIQUE (`group_id`, `permission_id`);
ALTER TABLE `auth_user_groups` ADD CONSTRAINT `auth_user_groups_user_id_6a12ed8b_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
ALTER TABLE `auth_user_groups` ADD CONSTRAINT `auth_user_groups_group_id_97559544_fk_auth_group_id` FOREIGN KEY (`group_id`) REFERENCES `auth_group` (`id`);
ALTER TABLE `auth_user_groups` ADD CONSTRAINT auth_user_groups_user_id_group_id_94350c0c_uniq UNIQUE (`user_id`, `group_id`);
ALTER TABLE `auth_user_user_permissions` ADD CONSTRAINT `auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
ALTER TABLE `auth_user_user_permissions` ADD CONSTRAINT `auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm` FOREIGN KEY (`permission_id`) REFERENCES `auth_permission` (`id`);
ALTER TABLE `auth_user_user_permissions` ADD CONSTRAINT auth_user_user_permissions_user_id_permission_id_14a6b632_uniq UNIQUE (`user_id`, `permission_id`);
COMMIT;
使用mysql命令行 逐条测试,发现下行指令报错,具体错误
mysql> CREATE TABLE `auth_user` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `password` varchar() NOT NULL, `last_login` datetime() NOT NULL, `is_superuser` bool NOT NULL, `username` varchar() NOT NULL UNIQUE, `first_name` varchar() NOT NULL, `last_name` varchar() NOT NULL, `email` varchar() NOT NULL, `is_staff` bool NOT NULL, `is_active` bool NOT NULL, `date_joined` datetime() NOT NULL);
- 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, `is_superuser` bool NOT NULL, `username` varchar(30) NOT NULL UNIQ' at line
对比django的报错信息,还有有区别的。但基本上可以获知是 (6) NOT NULL这部分指令的问题。
mysql> CREATE TABLE `auth_user` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `password` varchar() NOT NULL, `last_login` datetime NOT NULL, `is_superuser` bool NOT NULL, `username` varchar() NOT NULL UNIQUE, `first_name` varchar() NOT NULL, `last_name` varchar() NOT NULL, `email` varchar() NOT NULL, `is_staff` bool NOT NULL, `is_active` bool NOT NULL, `date_joined` datetime NOT NULL);
Query OK, rows affected
OK,没问题,查看数据库,表也存在了。last_login和date_joined字段的格式也没有问题
看来得看django如何配置了
https://www.techiediaries.com/how-to-reset-migrations-in-django-17-18-19-and-110/https://www.kawabangga.com/posts/3013
django无法同步mysql数据库 Error:1064的更多相关文章
- solr6.4.1搜索引擎同步mysql数据库
尚未成功启动solr的,请参考我的另一篇文章:http://www.cnblogs.com/zhuwenjoyce/p/6506359.html(solr6.4.1 搜索引擎启动eclipse启动) ...
- solr6.4.1搜索引擎(2)首次同步mysql数据库
尚未成功启动solr的,请参考我的另一篇文章:http://www.cnblogs.com/zhuwenjoyce/p/6506359.html(solr6.4.1 搜索引擎启动eclipse启动) ...
- django 中连接mysql数据库的操作步骤
django中连接mysql数据库的操作步骤: 1 settings配置文件中 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mys ...
- solr6.4.1搜索引擎(3)增量同步mysql数据库
尚未实现首次同步mysql数据库的,请参考我的另一篇文章http://www.cnblogs.com/zhuwenjoyce/p/6512378.html(solr6.4.1搜索引擎同步mysql数据 ...
- Django中使用mysql数据库并使用原生sql语句操作
Django自身默认使用sqlite3这个轻量级的数据库,但是当我们开发网站时,sqlite3就没有mysql好,sqlite3适合一些手机上开发使用的数据库. 准备的软件mysql数据库,版本5.7 ...
- Logstash同步mysql数据库信息到ES
@font-face{ font-family:"Times New Roman"; } @font-face{ font-family:"宋体"; } @fo ...
- 使用canal增量同步mysql数据库信息到ElasticSearch
本文介绍如何使用canal增量同步mysql数据库信息到ElasticSearch.(注意:是增量!!!) 1.简介 1.1 canal介绍 Canal是一个基于MySQL二进制日志的高性能数据同步系 ...
- 使用go-mysql-elasticsearch同步mysql数据库信息到ElasticSearch
本文介绍如何使用go-mysql-elasticsearch同步mysql数据库信息到ElasticSearch. 1.go-mysql-elasticsearch简介 go-mysql-elasti ...
- 使用logstash同步mysql数据库信息到ElasticSearch
本文介绍如何使用logstash同步mysql数据库信息到ElasticSearch. 1.准备工作 1.1 安装JDK 网上文章比较多,可以参考:https://www.dalaoyang.cn/a ...
随机推荐
- npm使用国内镜像的方法
一.通过命令配置1. 命令 npm config set registry https://registry.npm.taobao.org 2. 验证命令 npm config get registr ...
- 20190316xlVba_设置行高的改进方案
Public Sub AutoSetRowHeight(ByVal sht As Worksheet, Optional RowsInOnePage As Long) Dim BreakRow As ...
- Mysql5.7出现this is incompatible with sql_mode=only_full_group_by
vi /etc/my.cnf #编辑mysql配置文件 在 [mysqld]和[mysql]下添加 sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZE ...
- dedecmsv5.7 前台模版里输出变量
如何在PHP文件查询出来的数据赋值给前端页面展示出来? 例如: PHP文件:agency.php require_once(dirname(__FILE__) . '/../../include/co ...
- Luffy之支付宝支付开发API
发起支付 接入支付宝 支付的大致流程如下图: 部分节点详解: 沙箱环境 是支付宝提供给开发者的 ...
- js实现数组去重
1.遍历 let aArray = [1,2,2,3,3,"3"] let bArray = [] for(const a of aArray){ let index = bArr ...
- scrapy python2升级python3遇到的坑
换成Python3首先pycharm先执行: 然后看代码自己所需要的第三方库都要重新装 然后执行代码: 遇到这样的错如下: SyntaxError: invalid syntax 先检查print 所 ...
- Django--filter(**kwargs)
Django--filter(**kwargs)-exclude(**kwargs) filter() 说明: 数据的过滤 返回Queryset包含与给定查找参数匹配的新对象.这里需要特别注意的地方就 ...
- LAMP架构上(一)
第十七课LAMP架构上(一) 目录 一.LAMP架构介绍 二.MySQL.MariaDB介绍 三.MySQL安装 四.MariaDB安装 五.Apache安装 六.安装PHP5 七.安装PHP7 八. ...
- 类的构造器-init和new
提到构造器,大家都会想到 __init__,那么__new__是什么?也是构造器. init 构造器 都很熟悉了,直接上代码 class MyClass(object): def __init__(s ...