gpt4 book ai didi

mysql - 1292 列 'updated_at' 的日期时间值不正确

转载 作者:行者123 更新时间:2023-12-02 00:47:33 26 4
gpt4 key购买 nike

我在 Laravel 中创建了一个带有标准日期时间列的表:

Schema::create('lists', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('ref');
$table->string('provider');
$table->timestamps();
$table->softDeletes();

$table->unique(['provider', 'ref']);
});

当我尝试使用 Eloquent 创建一个简单的记录时:
List::updateOrCreate([
'provider' => 'test',
'ref' => 'S4d3g'
], [
'name' => 'Plan'
]);

我收到此消息(这是原始控制台输出,因此请忽略缺少引号):
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2020-03-08 02:25:07' for column 'updated_at' at row 1 (SQL: insert into `lists` (`provider`, `ref`, `name`, `updated_at`, `created_at`) values (test, S4d3g, Plan, 2020-03-08 02:25:07, 2020-03-08 02:25:07))

在数据库上手动运行查询作为原始 SQL 也不起作用:
insert into `lists` (`provider`, `ref`, `name`, `updated_at`, `created_at`) values ('test', 'S4d3g', 'Plan', '2020-03-08 02:25:07', '2020-03-08 02:25:07')

我正在使用 MySQL 5.7。

令人费解的是,如果我将日期更改为凌晨 2 点以外的任何日期,它会起作用:
insert into `lists` (`provider`, `ref`, `name`, `updated_at`, `created_at`) values ('test', 'S4d3g', 'Plan', '2020-03-08 01:25:07', '2020-03-08 01:25:07')
insert into `lists` (`provider`, `ref`, `name`, `updated_at`, `created_at`) values ('test', 'S4d3g', 'Plan', '2020-03-08 03:25:07', '2020-03-08 03:25:07')

什么可能导致这种奇怪的 MySQL 级别不喜欢时间戳上的凌晨 2 点?

最佳答案

看来您在美国,所在的时区是 daylight saving time just started .

因此,今天不存在凌晨 2 点。

March 8th, 2020 - Daylight Saving Time Starts

When local standard time is about to reach
Sunday, March 8th, 2020, 02:00:00 clocks are turned forward 1 hour to
Sunday, March 8th, 2020, 03:00:00 local daylight time instead.

Sunrise and sunset will be about 1 hour later on March 8th, 2020 than the day before. There will be more light in the evening.


DATETIME在 MySQL 中使用本地时间(时区可以通过多种方式设置),在您的情况下,它可能是您的本地时间,这就是您遇到此问题的原因。如果您实际上是指 UTC,则必须首先使用 SET time_zone = "+00:00" 将时区设置为 UTC或者通过设置正确的 global configuration .

由于您的 PHP 库正在生成此(无效)时间,因此我假设您在 PHP 和 MySQL 使用的时区之间存在不匹配。

关于mysql - 1292 列 'updated_at' 的日期时间值不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60584021/

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