The default setting method for datetime type in mysql, mysqldatetime

Source: Internet
Author: User

The default setting method for datetime type in mysql, mysqldatetime

An error occurred while modifying the default datetime value through the navicat client.

The field type of the database table is datetime. The default value is NULL. When the default value is set to the current time on the interface, the message "1067-Invalid default value for 'create _ TM '" is displayed '", this problem does not occur during table creation, for example, the table creation statement:

Create table 'app _ info1' ('id' bigint (21) unsigned not null AUTO_INCREMENT COMMENT 'Primary key id', 'app _ id' varchar (30) default null comment 'app Code', 'app _ name' varchar (30) default null comment 'app name', 'package _ name' varchar (100) default null comment 'package name', 'version' int (11) default null comment' version', 'version _ name' varchar (20) default null comment' version name ', 'icon _ url' varchar (512) default null comment 'icon address', 'Download _ url' varchar (512) default null comment', 'summary 'varchar (512) default null comment 'summary', 'desc' varchar (512) default null comment' description information', 'app _ status' int (4) DEFAULT '0' comment' status 0: available, 1: Delete ', 'create _ time' datetime DEFAULT CURRENT_TIMESTAMP COMMENT' creation time', 'create _ user' varchar (30) default null comment 'creator ', 'modify _ time' datetime DEFAULT CURRENT_TIMESTAMP comment' modify time', 'modify _ user' varchar (30) default null comment' modifier ', primary key ('id ')) ENGINE = InnoDB AUTO_INCREMENT = 2 default charset = utf8;

Then I tried to directly modify the field through the script, which is also OK, as shown below:

Alter table ts_role MODIFY column create_tm datetime default CURRENT_TIMESTAMP COMMENT 'creation time'

Of course, I have installed Mysql 5.6 or above, but I have not tried any other versions.

The default value setting method for datetime type in mysql is all the content shared by the editor. I hope you can give us a reference and support the help house.

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.