当前位置:网站首页>ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
ERROR 1067 (42000): Invalid default value for ‘end_time‘ Mysql
2022-06-28 23:16:00 【waiting971118】
1、报错信息
在执行下面的Sql语句时 ,出现错误信息:ERROR 1067 (42000): Invalid default value for ‘end_time’
CREATE TABLE seckill1(
`seckill_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '商品库存id',
`name` varchar(120) NOT NULL COMMENT '商品名称',
`number` int NOT NULL COMMENT '库存数量',
`start_time` timestamp NOT NULL COMMENT '秒杀开启时间',
`end_time` timestamp NOT NULL COMMENT '秒杀结束时间',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY(seckill_id),
key idx_start_time(start_time),
key idx_end_time(end_time),
key idx_create_time(create_time)
)ENGINE = InnoDB AUTO_INCREMENT = 1000 DEFAULT CHARSET = utf8 COMMENT = '秒杀库存表';错误信息如下:
2、解决方案
(1) 查看 sql_mode :
show session variables like '%sql_mode%(2) 修改sql_mode(去掉NO_ZERO_IN_DATE,NO_ZERO_DATE) :
set sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';(3) 重新执行1中的sql语句:
显示创建表成功
三步的执行截图如下:
3、出现报错的原因
(1)错误详解
表中的第一个TIMESTAMP列(即1的sql语句中的start_time行)(如果未声明为NULL或显示DEFAULT或ON UPDATE子句)将自动分配DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP属性。
第一个之后的TIMESTAMP列(即1的sql语句中的end_time行)如果未声明为NULL或显示DEFAULT子句)将自动分配DEFAULT ‘0000-00-00 00:00:00’(零时间戳),这不满足sql_mode中的NO_ZERO_DATE而报错。
(2)解决方法(三种)注:2中的解决方法只是针对创建的这张表
方法一:先执行select @@sql_mode,复制查询出来的值并将其中的NO_ZERO_DATE删除,然后执行set sql_mode = '修改后的值'。此方法只在当前会话中生效
方法二:先执行select @@global.sql_mode,复制查询出来的值并将其中的NO_ZERO_DATE删除,然后执行set global sql_mode = '修改后的值',此方法在当前服务中生效,重新MySQL服务后失效
方法三:在mysql的安装目录下,打开my.ini或my.cnf文件,新增下面这一行,
sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION, 然后重启mysql。此方法永久生效
边栏推荐
- SqlServer复习
- [word Tutorial Series Part 1] how to remove arrows in word tables
- 运维排查-使用hcache插件排查Buffer/cache占用过高
- When dialogfragment's onstop is completely invisible, call disass to exit the interface and report an error. Solution
- At the end of June, how many people in Kangkang are ready to change jobs
- [stm32 Hal library] RTC and BKP drives
- Wechat red envelope cover making tutorial and use guide with link jump
- 笔记
- Business atlas in super factory
- Didn't find an internship. He summed it up
猜你喜欢

Online text filter less than specified length tool
![Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding
![[API packet capturing in selenium automation] installation and configuration of browsermobproxy](/img/67/3e15b2191ee23a8c4453aad007651d.png)
[API packet capturing in selenium automation] installation and configuration of browsermobproxy
![Leetcode 324 swing sort ii[sort double pointer] the leetcode path of heroding](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
Leetcode 324 swing sort ii[sort double pointer] the leetcode path of heroding

With a monthly salary of 60000 yuan, such people began to be robbed after the Internet "reduced costs and increased efficiency"
![LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路

Linq连表查询

2022年PMP项目管理考试敏捷知识点(4)

Flowable boundary timer

Lecun predicts AgI: big model and reinforcement learning are both ramps! My world model is the new way
随机推荐
Is it safe to open a stock account online?
Master the usage of const
[sword finger offer] 50 First character that appears only once
A password error occurred when docker downloaded the MySQL image to create a database link
【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码
Online linear programming: Dual convergence, new algorithms, and regret bounds
[stm32 HAL库] RTC和BKP驱动
Junior, it's not easy!
C interview questions_ 20220627 record
When dialogfragment's onstop is completely invisible, call disass to exit the interface and report an error. Solution
At the end of June, how many people in Kangkang are ready to change jobs
没找到实习,他总结了这些
【Flutter 問題系列第 71 篇】Flutter 中 Uint8List 和 Image 之間的相互轉換
Do you know all the wonderful functions of the vlookup function?
自媒体行业内卷严重:企业自媒体应该何去何从
深入虚拟内存(Virtual Memory,VM)
C# 面试题目_20220627记录一下
[flutter issues Series title 71] Mutual Conversion between uint8list and Image in flutter
Production environment sonarqube installation
想问问,股票开账户如何优惠开户?网上开户安全么?