MySQL Set default value current_timestamp for a datetime type field, throwing Invalid default value for error

Source: Internet
Author: User
Tags mysql version

Causes

In the local database execution test platform database structure file Data_struct.sql, the execution of the build table statement resembles the following:

CREATE TABLE' demo ' (' ID ' )int(Ten) unsigned not NULLAuto_increment,' name ' Longtext COLLATE utf8_bin,' Create_time 'datetime  not NULL DEFAULT Current_timestamp, ' Update_time 'datetime  not NULL DEFAULT Current_timestamp,  PRIMARY KEY(' id ')) ENGINE=InnoDB auto_increment= - DEFAULTCHARSET=UTF8 COLLATE=Utf8_bin;

The following errors were found during the process

1067 (42000defaultfor'create_time' )

After

After Google for reasons, and combined with their own situation, found the cause of the problem.

The reasons for netizens ' guesses are:

The Sql_mode settings in the 1.mysql configuration are not correct (the first reaction is this), check your configuration did not find the problem

Reason for the 2.mysql version (root cause of the problem)

Results

After seeing the version, I checked the version of MySQL and found that the test platform was version 5.7 and was using version 5.5. Using Current_timestamp as the default value for DateTime is only supported in versions after 5.6.

"Solutions"

Upgrade the local database version.

MySQL Set default value current_timestamp for a datetime type field, throwing Invalid default value for error

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.