Incorrect datetime value in MySQL 8 - How to fix?

Viewed 1034
INSERT INTO `projects` (`name`, `created_at`) VALUES ('test', '2015-01-21 04:09:46');
INSERT INTO `projects` (`name`, `created_at`) VALUES ('test', '2016-03-27 01:29:59');

The first query run good, the second given an error: Error in query (1292): Incorrect datetime value: '2016-03-27 01:29:59' for column 'created_at' at row 1

The sql_mode is:

STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

The table:

DROP TABLE IF EXISTS `projects`;
CREATE TABLE `projects` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

MySQL version: 8.0.19

1 Answers

Please change created_at data type to created_at datetime DEFAULT NULL

Then try to insert the value.

Related