- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
CREATE TABLE seckill (
`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='秒杀库存表';
当我尝试使用之前的查询创建表时,这是我得到的错误:
ERROR 1067 (42000): Invalid default value for 'end_time'
我该如何解决这个问题?
最佳答案
MySQL 以一种特殊的方式处理timestamp
,这在documentation 中很难找到。当您不知道要查找什么时:
In MySQL, the TIMESTAMP data type differs in nonstandard ways from other data types:
TIMESTAMP columns not explicitly declared with the NULL attribute are assigned the NOT NULL attribute. (Columns of other data types, if not explicitly declared as NOT NULL, permit NULL values.) Setting such a column to NULL sets it to the current timestamp.
The first TIMESTAMP column in a table, if not declared with the NULL attribute or an explicit DEFAULT or ON UPDATE clause, is automatically assigned the DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP attributes.
TIMESTAMP columns following the first one, if not declared with the NULL attribute or an explicit DEFAULT clause, are automatically assigned DEFAULT '0000-00-00 00:00:00' (the “zero” timestamp). For inserted rows that specify no explicit value for such a column, the column is assigned '0000-00-00 00:00:00' and no warning occurs.
Those nonstandard behaviors remain the default for TIMESTAMP but as of MySQL 5.6.6 are deprecated and this warning appears at startup:
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
Please use --explicit_defaults_for_timestamp server option
(see documentation for more details).
这意味着您的第二个 timestamp not null
列将获得隐式默认值 '0000-00-00 00:00:00'
,这在与 NO ZERO DATE
组合和 strict sql 模式(默认情况下在 MySQL 5.7 中启用)并导致错误。
要解决您的问题,请启用选项 --explicit_defaults_for_timestamp
.它按照您的预期处理 timestamp
列(并且无论如何将成为 future MySQL 版本中的默认行为),或者允许它们为 null
。
关于mysql - 错误 1067 (42000) : Invalid default value for 'end_time' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39545124/
我从 Facebook Insights API 请求数据,粒度设置为一天,让我们以点赞为例。我的要求是:PAGEID/insights/page_fan_adds_unique/day 响应看起
我正在 2 个带有 #start_time 和 #end_time id 的文件上使用 jQuery 时间选择器插件 ( https://github.com/trentrichardson/jQue
我有一张像这样的 table start_time end_time 2016-10-26 08:45:00 2016-10-27 09:45:00 2016
我有一个名为“activity”的 MySQL 表,其中包含事件数据。重要的列是“start_time”和“end_time”,其中包含字符串(YYYY-MM-DD)来表示事件的开始和结束时间。 我想
我的项目使用的是 laravel 6 和 mysql 5.7,我在模型中放置了两列 start_time 和 end_time ,并且都在 timestamp 类型。在操作中,我创建一条记录并初始化
我在模型中有 start_time 和 end_time 数据字段,我想在 start_time 晚于 end_time end_time: raise forms.Valid
如何获得开始时间和结束时间之间的半小时差异 $('#OutletEvents_start_time').datetimepicker({ datepicker:false, forma
CREATE TABLE seckill ( `seckill_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '商品库存id', `name` VARC
这里一定有一些简单的东西被忽略了...... 我一直在尝试各种方法来创建基本的 IceCube 计划 ( https://github.com/seejohnrun/ice_cube )。总体目标是使
我在数据库中有一个下表。 id | list_id |venue_id |name | start_date | end_date |start_time | end_time 1
假设这是我的数据框: date start_time end_time 1/1/2018 20:00 21:00 1/1/2018 23:00 1
我正在制作时间表提交/批准功能,目前正在处理 pending.php 页面,经理/管理员可以转到 pending.php 并查看待审核的时间表... 我现在的代码是: list($qh,$num) =
我有一个 end_time,我想为 end_time.utc - Time.now 创建一个计时器。但是,当我减去该值时,我得到一个类似 23510.29642 的 float ,我发现它表示小时、分
我是一名优秀的程序员,十分优秀!