1970 年之前的默认日期值,默认值无效
当我尝试为日期字段设置默认值时,我不断收到此错误: “创建”的默认值无效
ALTER TABLE artwork CHANGE COLUMN created created TIMESTAMP NOT NULL DEFAULT '1954-09-18 00:00:00' AFTER updated;
我每年都尝试过,我注意到在 1970 年之前,mysql 拒绝该日期。我的意思是这不是一个大问题,我真的不需要默认日期为 1954 年,如果我想要那个日期,那主要是出于象征性原因。
假设我的问题没有直接的解决方案,那么我的问题是:为什么 mysql 拒绝 1970 年之前的默认日期?
谢谢
i keep getting this error when trying to set up a default value for a date field:
Invalid default value for 'created'
ALTER TABLE artwork CHANGE COLUMN created created TIMESTAMP NOT NULL DEFAULT '1954-09-18 00:00:00' AFTER updated;
I've tried every year and i notice that prior to 1970, mysql rejects the date. I mean it's not a big problem, i really don't need the default date to be 1954, if i want that date it is mostly for symbolic reasons.
Assuming that there is no direct solution for my issue, then my question is: why is it that mysql rejects default dates prior to 1970 ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不熟悉 mysql,但 Unix 时间戳(广泛使用)是自 1970-01-01 00:00:00 GMT 以来的秒数。如果 mysql 在内部使用该格式,它可能不喜欢带有负值的时间戳。
编辑:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html:
I'm not familiar with mysql, but Unix timestamps (which are widely used) are a count of seconds since 1970-01-01 00:00:00 GMT. If mysql uses that format internally, it probably doesn't like a timestamp with a negative value.
EDIT:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html :
MySQL 的 TIMESTAMP 类型是一个表示Unix 时间的计数器。这是自 1970 年 1 月 1 日开始以来的秒数。为什么它被签名(最大日期是 2038 年——如果没有签名则允许时间的一半)并且不允许日期在 1970-2038 年之外范围超出了我的范围。另请参阅有关此列类型的 MySQL 文档。
DATETIME 列类型使用两倍的空间(8 个字节),但支持的范围是“1000-01-01 00:00:00”到“9999-12-31 23:59:59”。
MySQL's TIMESTAMP type is a counter representing Unix time. That's the number of seconds since the start of January 1, 1970. Why it is signed (maximum date is in 2038 -- half the time that would would be allowable if it were unsigned) and doesn't allow dates outside the 1970-2038 range is beyond me. See also the MySQL documentation on this column type.
The DATETIME column type uses twice the space (8 bytes), but the supported range there is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.