mysql数据库运行sql:datetime(0) NULL DEFAULT NULL报错【杭州多测师_王sir】

一、错误信息

CREATE TABLE `file`  (
  `id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件md5',
  `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `create_time` datetime(0) NULL DEFAULT NULL,
  `update_time` datetime(0) NULL DEFAULT NULL,,
  PRIMARY KEY (`id`)
)

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 '(0) NULL  DEFAULT NULL,
  `update_time` datetime(0) NULL DEFAULT NULL,
  `tena' at line 3

二、解决方法

问题发现是第三行,那就是datetime字段,在网上查询是mysql版本时间字段不能设置为0。给一个默认值,直接删除 (0) NULL

CREATE TABLE `file`  (
  `id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件md5',
  `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  ##默认是1970-01-01 00:00:00,中国时间要加8
  `create_time` datetime DEFAULT '1970-01-01 08:00:00',
  `update_time` datetime DEFAULT '1970-01-01 08:00:00',
  PRIMARY KEY (`id`)
)

你可能感兴趣的:(数据库,mysql,sql,android)