【问题标题】:Laravel : Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:00:00'Laravel:无效的日期时间格式:1292 不正确的日期时间值:'2021-03-14 02:00:00'
【发布时间】:2021-03-14 22:24:08
【问题描述】:

我收到很多日期时间格式无效错误

[2021-03-14 02:00:00] production.ERROR: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:00:00' for column `xxxxxxx`.`users`.`last_activity` at row 1 (SQL: update `users` set `last_activity` = 2021-03-14 02:00:00, `users`.`updated_at` = 2021-03-14 02:00:00 where `id` = 2561) {"userId":2561,"exception":"[object] (Illuminate\\Database\\QueryException(code: 22007): SQLSTATE[22007]:
[stacktrace]


[2021-03-14 02:58:46] production.ERROR: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:58:46' for column `xxxx`.`posts`.`updated_at` at row 1 (SQL: update `posts` set `view` = `view` + 1, `posts`.`updated_at` = 2021-03-14 02:58:46 where `id` = 43018) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 22007): SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:58:46' for column `xxxx`.`posts`.`updated_at` at row 1 (SQL: update `posts` set `view` = `view` + 1, `posts`.`updated_at` = 2021-03-14 02:58:46 where `id` = 43018) at /home/xxxx/xxxxx/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 22007): SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2021-03-14 02:58:46' for column `xxxx`.`posts`.`updated_at` at row 1 at /home/xxxx/xxxx/vendor/laravel/framework/src/Illuminate/Database/Connection.php:483)
[stacktrace]

错误开始于:2021-03-14 02:00:00

结束于:2021-03-14 02:58:46

一年多来一切正常

一切恢复正常没有任何代码更改

有人可以帮我了解发生了什么吗?

config/app.php

  1. '时区' => '非洲/突尼斯',

表结构

数据库服务器

  • 服务器:通过 UNIX 套接字的本地主机
  • 服务器类型:MariaDB
  • 服务器连接:未使用 SSL 文档
  • 服务器版本:10.3.27-MariaDB-log-cll-lve - MariaDB 服务器
  • 协议版本:10
  • 用户:xxx@localhost
  • 服务器字符集:cp1252 西欧 (latin1)

【问题讨论】:

  • @Haytheme Dridi,你做了什么来解决这个错误?

标签: laravel laravel-5


【解决方案1】:

问题是因为夏令时 (DST)。

您的应用设置为“Africa/Tunis”,我认为它无法识别 DST。但这是数据库错误,而不是应用程序错误。您的数据库显然使用了可识别 DST 的时区。

DST 于 2021 年 3 月 14 日 02:00:00 开始。因此,2021-03-14 02:00:00 和 2021-03-14 02:59:59 之间的时间不存在,并且不是有效时间,从而导致您收到错误。

【讨论】:

  • 那么我该如何解决这个问题?我的应用时区是 America/Los_Angeles 以及我的服务器时区。服务器是centos 8。我必须在其他任何地方更改时区吗?
  • @AlauddinAhmed,您没有指定您使用的数据库,但我建议您查看数据库上的文档以了解它如何确定要使用的时区。
猜你喜欢
  • 2019-07-31
  • 2018-09-11
  • 1970-01-01
  • 1970-01-01
  • 2017-11-08
  • 1970-01-01
  • 1970-01-01
  • 2012-07-08
  • 1970-01-01
相关资源
最近更新 更多