gpt4 book ai didi

MySQL:尝试在时间戳中插入值会引发错误

转载 作者:可可西里 更新时间:2023-11-01 07:07:20 25 4
gpt4 key购买 nike

我有一个包含此列的表格:

last_modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

看起来我无法插入带有自定义时间戳的行,我收到此错误:

Incorrect datetime value: '1145868501' for column 'last_modified' at row 1

我试图用来自另一个表的数据填充此表,另一个表只有一个 creation_time 字段,它是一个 DATETIME,所以我使用 UNIX_TIMESTAMP(creation_time) 来填充时间戳。

我认为带有“DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP”的时间戳列阻止我插入自己的东西,对吗?如果是的话,官方文档在哪里,最好的解决方案是什么?先创建一个简单的时间戳,然后在插入数据后更改表?

谢谢!

编辑:因为人们建议我不要使用 UNIX_TIMESTAMP,我不得不说我一开始不想使用它,但我遇到了这种错误:日期时间值不正确:列“last_modified”的“2010-03-28 02:15:51”所以我想我必须插入一个“真实的”时间戳......

最佳答案

您可以在 TIMESTAMP 中显式插入一个值柱子。阅读:TIMESTAMP Properties

The auto-update TIMESTAMP column, if there is one, is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. If all other columns are set to their current values, the TIMESTAMP column does not change. Automatic updating does not apply if the TIMESTAMP column is explicitly assigned a value other than NULL.


更新

嘿嘿,发生错误是因为 - 好吧 - 没有带 '2010-03-28 02:15:51' 的日期时间!这是在夏令时间隙(通常出现在三月的某一天,介于 02:00 - 03:0003:00 - 04:00 之间。

参见:Daylight Saving Time解释。

关于MySQL:尝试在时间戳中插入值会引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9354133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com