MariaDB - Invalid default value for 'created'

Viewed 30

I use MariaDB 5.5.68 and I get an error when I try to import database to server

#1067 - Invalid default value for 'created'

Code part

CREATE TABLE `wp_payments` (
  `id` int(10) UNSIGNED NOT NULL,
  `order_id` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `amount` int(10) UNSIGNED DEFAULT '0',
  `phone_number` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `payment_id` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `failed_reason` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `salt` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `status` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT 'pending'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

How to solve this problem?

1 Answers

You need to change the type of column created from datetime to TIMESTAMP

CREATE TABLE `wp_payments` (
  `id` int(10) UNSIGNED NOT NULL,
  `order_id` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `amount` int(10) UNSIGNED DEFAULT '0',
  `phone_number` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `payment_id` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `failed_reason` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `salt` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT '',
  `status` varchar(36) COLLATE utf8mb4_unicode_ci DEFAULT 'pending'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

DB Fiddle Demo

Related