Use of CURRENT_TIMESTAMPAs we all know, MySQL's date type can use CURRENT_TIMESTAMP to specify the default value, but this is related to the MySQL version and the specific type of the date. Only versions after 5.6 can use CURRENT_TIMESTAMP as the default value of DATETIME. For example: ALTER TABLE t_user ADD update_time DATETIME DEFAULT CURRENT_TIMESTAMP In versions prior to 5.6, when CURRENT_TIMESTAMP is used as the default value, the following error will occur
Prior to MySQL 5.6.5, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP only applies to TIMESTAMP, and at most one TIMESTAMP field in a table is allowed to use this feature. As of MySQL 5.6.5, DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP applies to both TIMESTAMP and DATETIME columns, and to an unlimited number of columns. timestamp using CURRENT_TIMESTAMP reports an errorThe project has the following error:
The data model is as follows: /* Creation time cannot be empty */ createTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time', /* Update time cannot be empty*/ updateTime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update time', After a series of troubleshooting, it was found that the problem was caused by the global variable "explicit_defaults_for_timestamp" in different versions of MySQL database. -- View the default value of explicit_defaults_for_timestamp SHOW GLOBAL VARIABLES LIKE "explicit_defaults_for_timestamp"; -- Modify the default value of explicit_defaults_for_timestamp SET @@global.explicit_defaults_for_timestamp=OFF; When the parameter value is "ON": The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of using CSS3's var() to change scss variable values at runtime
>>: Example code for implementing page floating box based on JS
1. Check the character set 1. Check the MYSQL dat...
Preface During the stress test, if the most direc...
When I was writing a project yesterday, I needed ...
MySQL advantage: Small size, fast speed, low tota...
Delete a file by its inode number First use ls -i...
A set of projects for training react+ts Although ...
1. Download the MySQL 5.7 installation package fr...
Table of contents Install Tomcat with Docker Use ...
The task of concurrency control in a database man...
The datetime type is usually used to store time i...
Why use prettier? In large companies, front-end d...
Preface Mobile devices have higher requirements f...
MySQL slow log is a type of information that MySQ...
1. Introduction to Varnish Varnish is a high-perf...
Preface In the Linux kernel, in order to be compa...