今天想要把一张已经有的数据表中记录创建日期的一列设置成自动插入当前时间的模式,但是怎么改都报错:
ERROR 1067 (42000): Invalid default value for 'UpdateTime'
1
于是就从百度上搜集信息,得知想要这样功能的列,需要在建表的时候就设置好,不知道建表之后是不能修改还是我没有找到正确的方法,在这种情况下我尝试重新建表,然后成功得到我想要的具有自动记录插入时间和最后修改时间的功能的列,在这里记录一下,建表语句如下:
create table table_timestamp(
message_pk bigint not null auto_increment,
message_content varchar(99),
CreateTime timestamp not null default current_timestamp comment '创建时间',
UpdateTime timestamp not null default current_timestamp on update current_timestamp comment '修改时间',
primary key(message_pk)
);
注意:
经过检查定位到下面语句,经过网上查询的资料发现,是默认的时间格式’0000-00-00 00:00:00’和timestamp的时间范围不符合导致的问题,将默认的时间格式改为CURRENT_TIMESTAMP或者是’1970-01-01 00:00:01’以上就可以正常导入了。
以上注意是引用自A2Z_development博客的内容
————————————————
版权声明:本文为优快云博主「多做项目」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/weixin_43249665/article/details/89107533