MySQL <column> </column>的默认值无效

时间:2014-05-09 14:37:34

标签: mysql default

执行此声明时:

CREATE TABLE MG_FOLDER (
  UUID CHAR(24) NOT NULL,
  NAME VARCHAR(100),
  OWNER VARCHAR(32),
  CREATED TIMESTAMP,
  MODIFIED TIMESTAMP,
  ARCH BOOLEAN,
  FOLDER_UUID CHAR(24),
  SERIAL INTEGER,
  CONSTRAINT FOLDER_PK PRIMARY KEY(UUID)
) ENGINE = InnoDB

我收到此错误:

Invalid default value for 'MODIFIED'

我认为我没有为MODIFIED设置默认值,那导致问题的原因是什么?

1 个答案:

答案 0 :(得分:0)

您需要在COLUMNS TIMESTAMP任意DEFAULT CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(), or NOW()和其他DEFAULT NULL或两者都指定默认值为null,但必须指定...

CREATE TABLE IF NOT EXISTS `MG_FOLDER` (
  `UUID` char(24) COLLATE utf8_unicode_ci NOT NULL,
  `NAME` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `OWNER` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `CREATED` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `MODIFIED` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ARCH` tinyint(1) DEFAULT NULL,
  `FOLDER_UUID` char(24) COLLATE utf8_unicode_ci DEFAULT NULL,
  `SERIAL` int(11) DEFAULT NULL,
  PRIMARY KEY (`UUID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;