S
S
Sergey Beloventsev2018-06-18 15:13:15
MySQL
Sergey Beloventsev, 2018-06-18 15:13:15

Why does this MySQL error occur?

here is a request

CREATE TABLE `main_documents` (
  `id` int(11) NOT NULL,
  `employee_id` int(11) DEFAULT NULL,
  `citizenship_id` int(11) DEFAULT NULL,
  `document_type_id` int(11) DEFAULT NULL,
  `first_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `last_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `middle_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `birthday` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `hometown` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `issue_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `expiration_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `gender` int(11) DEFAULT NULL,
  `series` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `number` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `scan_id` int(11) DEFAULT NULL,
  `issued_by` text COLLATE utf8_unicode_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

gives such an error
#1067 - Invalid default value for 'issue_date'

honestly tried to google but could not understand what the problem is

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Lyskov, 2018-06-18
@Vlatqa

timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
should be a timestamp, 0000-00-00 00:00:00 - this is not a timestamp

A
Alexey Ukolov, 2018-06-18
@alexey-m-ukolov

This is an invalid date that worked in older versions of Mysql due to a misunderstanding. In Mysql 8, this misunderstanding can be corrected with a special NO_ZERO_DATE flag , which you apparently have enabled.
And in 5.7 there was STRICT MODE .
Not to mention that your column is of type timestamp.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question