Mysql 建表时报错 invalid ON UPDATE clause for 'start_time' column
2019-08-23 14:36
253 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/miracleoa/article/details/100033771
文章目录
一、错误源码:
DROP TABLE IF EXISTS `tb_promotion`; CREATE TABLE `tb_promotion` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '促销活动id', `type` enum('0','1','2','3') NOT NULL DEFAULT '0' COMMENT '活动类型,目前可选的有:0没有促销,1满减,2满额送抵扣券,3秒杀', `description` varchar(255) NOT NULL DEFAULT '' COMMENT '促销活动说明', `condition` bigint(20) DEFAULT '0' COMMENT '满减条件,秒杀的话设置为0', `reduction` bigint(20) DEFAULT '0' COMMENT '满减后的折扣金额', `seckill_price` bigint(20) DEFAULT '0' COMMENT '秒杀价格,如果是秒杀活动,需要填写', `coupon_id` bigint(20) DEFAULT '0' COMMENT '满额送券,关联的优惠券id', `targets` varchar(255) NOT NULL DEFAULT '' COMMENT '作用的目标sku的id拼接,以'',''拼接', `start_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP, `end_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
二、错误原因,及解决办法:
- 由于低版本的mysql不支持两个
TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
,因此采用触发器的方式来解决这个问题。以下是解决后的源码:
CREATE TABLE `tb_promotion` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '促销活动id', `type` enum('0','1','2','3') NOT NULL DEFAULT '0' COMMENT '活动类型,目前可选的有:0没有促销,1满减,2满额送抵扣券,3秒杀', `description` varchar(255) NOT NULL DEFAULT '' COMMENT '促销活动说明', `condition` bigint(20) DEFAULT '0' COMMENT '满减条件,秒杀的话设置为0', `reduction` bigint(20) DEFAULT '0' COMMENT '满减后的折扣金额', `seckill_price` bigint(20) DEFAULT '0' COMMENT '秒杀价格,如果是秒杀活动,需要填写', `coupon_id` bigint(20) DEFAULT '0' COMMENT '满额送券,关联的优惠券id', `targets` varchar(255) NOT NULL DEFAULT '' COMMENT '作用的目标sku的id拼接,以'',''拼接', `start_time` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `end_time` datetime not null, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; drop TRIGGER if EXISTS 'update_trigger'; delimiter CREATE TRIGGER 'update_trigger' BEFORE UPDATE on 'tb_order_status' for each row set new.'end_time' = now() delimiter;
相关文章推荐
- MySQL 使用异常:Invalid ON UPDATE clause for 'createTime' column
- Mysql 建表时报错 invalid ON UPDATE clause for 'create_date' column
- [Err] 1293 - there can be only one TIMESTAMP column with CURRENT_TIME in DEFAULT or ON UPDATE clause
- my[Err] 1067 - Invalid default value for 'update_time'
- MYSQL之You can't specify target table for update in FROM clause解决办法
- MySQL之You can't specify target table for update in FROM clause解决办法
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- MySQL 中 You can't specify target table '表名' for update in FROM clause错误解决办法
- mysql错误:1093-You can’t specify target table for update in FROM clause的解决方法
- MySQL [Err] 1093 - You can't specify target table 'test' for update in FROM clause
- [MySql]You can't specify target table for update in FROM clause 原因及解决办法
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- 关于mysql "You can't specify target table 'test_zb_scene' for update in FROM clause"的错误
- mysql错误:1093-You can’t specify target table for update in FROM clause的解决方法
- MySQL问题:You can't specify target table '表名' for update in FROM clause
- MySQL报错“ you can't specify the target table for ‘update’ in from clause”
- MYSQL之You can't specify target table for update in FROM clause解决办法
- MYSQL之You can't specify target table for update in FROM clause解决办法
- 处理MySQL删除数据时Error Code: 1093. You can't specify target table '表名' for update in FROM clause
- MySQL can’t specify target table for update in FROM clause