#1067-“时间戳”的默认值无效

时间:2020-08-11 21:13:50

标签: mysql database wordpress migration plesk

我将WordPress网站从使用Plesk的共享托管计划转移到了具有更新Plesk版本的VPS服务器。尝试上传MYSQL数据库时,出现以下错误:

错误 SQL查询:复制

CREATE TABLE `XZu2B8_wc_reserved_stock` (
  `order_id` bigint(20) NOT NULL,
  `product_id` bigint(20) NOT NULL,
  `stock_quantity` double NOT NULL DEFAULT 0,
  `timestamp` datetime NOT NULL DEFAULT current_timestamp(),
  `expires` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`order_id`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

MySQL表示:文档

#1067-“时间戳”的默认值无效

有人知道如何解决吗?

1 个答案:

答案 0 :(得分:1)

仅在mysql 5.6中引入

对于mysql 5.5,您需要以下触发器,并且需要删除默认值 首先创建表:

CREATE TABLE `XZu2B8_wc_reserved_stock` (
  `order_id` bigint(20) NOT NULL,
  `product_id` bigint(20) NOT NULL,
  `stock_quantity` double NOT NULL DEFAULT 0,
  `timestamp` datetime NOT NULL,
  `expires` datetime NOT NULL ,
  PRIMARY KEY (`order_id`,`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

然后创建触发器

DELIMITER $$

 CREATE TRIGGER before_insert_XZu2B8_wc_reserved_stock
 BEFORE INSERT ON XZu2B8_wc_reserved_stock
 FOR EACH ROW
 BEGIN
    IF NEW.`timestamp` IS NULL THEN
       SET NEW.`timestamp`= NOW();
    END IF;
    IF NEW.`expires` IS NULL THEN
       SET NEW.`expires`= NOW();
    END IF;
 END$$
 DELIMITER ;