【发布时间】: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
【问题讨论】:
-
显示您的插入语句和表定义
-
更新了问题