【问题标题】:Mysql Invalid datetime format: 1292 Incorrect datetime value when creating some dummy data for testingMysql Invalid datetime format: 1292 Incorrect datetime value when created some dummy data for testing
【发布时间】:2017-08-06 04:54:30
【问题描述】:

在表格中插入一些行时出现此错误:

SQLSTATE[22007]:无效的日期时间格式:1292 不正确的日期时间值:“2017-03-26 02:00:00”列“已创建” _在' 在第 1 行

我以正确的格式插入:Y-m-d H:i:s 那么导致问题的原因是什么?

更新:

CREATE TABLE `posts` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `excerpt` text COLLATE utf8mb4_unicode_ci,
  `body` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `image_path` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `image` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `slug` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `markdown` tinyint(1) NOT NULL DEFAULT '0',
  `published` tinyint(1) NOT NULL DEFAULT '0',
  `views` int(10) UNSIGNED NOT NULL DEFAULT '0',
  `user_id` bigint(20) UNSIGNED NOT NULL,
  `published_at` datetime DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

我正在使用 500 次重复的循环将虚拟数据插入此表中,它成功地插入了 472 个帖子,然后因上述错误而失败。

这是生成的 sql 查询的样子,我不是自己写的,但是当我使用 php 对象和方法进行创建等时,我使用的框架会生成它

    "query" => "insert into `posts` (`user_id`, `title`, `excerpt`, `body`, `s
lug`, `image`, `created_at`, `updated_at`, `published_at`, `published`, `views`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)3
8;5;208m"
    "bindings" => array:11 [
      0 => 1
      1 => "Enim autem et quis consequatur vel deleniti et."
      2 => "Voluptatibus nobis et et quaerat at inventore incidunt et qui ea co"
      3 => """
        Soluta distinctio dolorem ut officiis dolores quisquam esse sint. Repellendus est atque enim
 quia.\n
        """
      4 => "ab-itaque-facilis-culpa-suscipit-et-ratione-doloremque"

      5 => "post_img_1.jpg"
      6 => "2017-03-06 10:00:00"
      7 => "2017-03-06 10:00:00"
      8 => "2017-03-06 17:00:00"
      9 => true
      10 => 49
    ]
    "time" => 29.97

【问题讨论】:

  • 显示您的插入语句和表定义
  • 更新了问题

标签: mysql datetime


【解决方案1】:

您的数据存储在哪个时区?

我认为问题不是日期时间值的格式,而是值本身。

我注意到您的一些数据是意大利语的,导致错误的值是 2017-03-26 02:00:00,这实际上是意大利的无效日期时间,因为那是夏令时开始的时间。

意大利的时钟将从2017-03-26 01:59:59 跳转到2017-03-26 03:00:00,因此您尝试插入的值无效。

【讨论】:

  • 嗨,我不确定意大利语,您看到的文本是随机的 lorem ipsum 文本,用于在开发时插入虚拟文本。我在瑞典,你描述的意大利问题在瑞典也一样吗?
  • 哈哈,对不起。它是拉丁文;我不知道为什么我认为它是意大利的。是的,瑞典的夏令时是一样的,所以答案仍然适用。
猜你喜欢
  • 1970-01-01
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 2016-08-25
  • 1970-01-01
  • 2016-05-21
  • 2013-05-30
  • 2019-10-04
相关资源
最近更新 更多