当前位置:网站首页>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。此方法永久生效
边栏推荐
- Three communication skills in software testing
- [word Tutorial Series Part 1] how to remove arrows in word tables
- Cs5463 code module analysis (including download link)
- CS5463代码模块解析(包含下载链接)
- 复杂嵌套的对象池(4)——管理多类实例和多阶段实例的对象池
- 一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂
- Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
- Chapter II Classic synchronous exercises
- 论文解读(DCN)《Towards K-means-friendly Spaces: Simultaneous Deep Learning and Clustering》
- Interviewer: what is the internal implementation of strings in redis?
猜你喜欢

【Word 教程系列第 2 篇】Word 中如何设置每页的表格都有表头

This simple little function saves 213 hours for our production research team in half a year
![[word Tutorial Series Part 1] how to remove arrows in word tables](/img/c7/dc57002b0e9d433c4dfac15d53713d.png)
[word Tutorial Series Part 1] how to remove arrows in word tables

See fengzhixia | FENGZikai, the originator of Guoman, for exclusive sale of Digital Collections

note

Tanghongbin, Yaya live CTO: to truly localize, the product should not have the attribute of "origin"

LINQ linked table query

第四章 存储器管理练习

One card can sell tens of millions, and the business expansion is faster than that of players: you don't understand the Jianghu of star cards

VSCode里使用条件断点(基于GDB)
随机推荐
Mathematical knowledge: finding combinatorial number I - finding combinatorial number
Lost in cloud computing
[API packet capturing in selenium automation] installation and configuration of browsermobproxy
Master the usage of const
2022年PMP项目管理考试敏捷知识点(4)
计数排序和排序的稳定性
他原来是这么刷题的!
A password error occurred when docker downloaded the MySQL image to create a database link
Non scientific class! The road of self-study!
国盛证券开户是真的安全可靠吗
Code example of hiredis
[stm32 Hal library] serial port communication
Junior, it's not easy!
Undefined symbol main (referred from entry9a.o).
没找到实习,他总结了这些
TDD and automated testing
Insomnia last night
[sword finger offer] 50 First character that appears only once
【Word 教程系列第 2 篇】Word 中如何设置每页的表格都有表头
On the necessity and solution of building a campus online teaching video convergence platform