如何将字段的默认值设置为“0000-00-00 00:00:00”?如果不能使用“0000-00-00 00:00:00”作为默认值,那么什么是基本有效的日期时间?
例如,这是创建文章表的SQL:
-- -----------------------------------------------------
-- Table `article`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `article` ;
CREATE TABLE IF NOT EXISTS `article` (
`article_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`url` VARCHAR(255) NOT NULL,
`title` VARCHAR(255) NOT NULL,
`date_from` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Set the article as new or featured from a datetime.',
`date_to` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Set the article as new or featured to a datetime.',
`backdated_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'The manual datetime that is modified or input by the user.',
`created_on` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'The permanent datetime when the article is created.',
`updated_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'The datetime when the article is updated on.',
PRIMARY KEY (`article_id`, `parent_id`, `template_id`),
UNIQUE INDEX `url_UNIQUE` (`url` ASC))
ENGINE = MyISAM
AUTO_INCREMENT = 66
COMMENT = 'Entity that holds the article with one-to-one properties.';
当我运行这个查询时,我收到了这个错误:
#1067 - Invalid default value for 'date_from'
NULL
。避免使用“魔术数字”。 - user330315