Share the pitfalls of MySQL's current_timestamp and their solutions

Share the pitfalls of MySQL's current_timestamp and their solutions

MySQL's current_timestamp pitfall

Report an error

Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

The answers on the Internet are basically as follows, but there is no specific solution

The reason for the solution is that when you set a timestamp to on updatecurrent_timestamp, other timestamp fields need to explicitly set default values

But if you have two timestamp fields, but only set the first one to current_timestamp and the second one has no default value, MySQL can successfully create the table, but not the other way around...

My Solution

Uninstall the current lower version of MySQL and install MySQL version 5.6 or higher. MySQL version 5.7 is recommended as it is relatively stable.

mysql5.5.23 current_timestamp problem

Today I created a new table with two fields: creation time and update time. Both default values ​​are the current time. An error occurs when executing SQL.

ERROR 1293 (HY000): Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

I have used this SQL in other projects and it works fine. Why can't it be executed successfully today? After confirming that there were no syntax errors in the sql, I checked the information online. It turns out that MySQL 5.5 only supports one time field in a table using CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP. But in 5.6 it supports multiple.

Original description

It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.

Solution

Remove the default creation time

Check the MySQL version number using the status command

這里寫圖片描述

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:
  • Solution to MySQL error TIMESTAMP column with CURRENT_TIMESTAMP
  • Analyzing the MySql CURRENT_TIMESTAMP function by example
  • Detailed explanation of TIMESTAMP usage in MySQL

<<:  How to prevent the scroll bar from affecting the page width when the scroll bar appears on the page

>>:  CSS animation combined with SVG to create energy flow effect

Recommend

How to add color mask to background image in CSS3

Some time ago, during development, I encountered ...

How to deploy services in Windows Server 2016 (Graphic Tutorial)

introduction Sometimes, if there are a large numb...

Native JS realizes the special effect of spreading love by mouse sliding

This article shares with you a js special effect ...

Vue3.x uses mitt.js for component communication

Table of contents Quick Start How to use Core Pri...

Detailed tutorial on installing MySQL database on Alibaba Cloud Server

Table of contents Preface 1. Uninstall MySQL 2. I...

Vue3 Vue CLI multi-environment configuration

Table of contents 1. Introduction 2. Switching 1....

Using js to achieve waterfall effect

This article example shares the specific code of ...

Detailed steps for yum configuration of nginx reverse proxy

Part.0 Background The company's intranet serv...

Tutorial on installing MYSQL5.7 from OEL7.6 source code

First, download the installation package from the...

Mysql command line mode access operation mysql database operation

Usage Environment In cmd mode, enter mysql --vers...

JavaScript canvas realizes dynamic point and line effect

This article shares the specific code for JavaScr...

Vue+thinkphp5.1+axios to realize file upload

This article shares with you how to use thinkphp5...

N ways to align the last row of lists in CSS flex layout to the left (summary)

I would like to quote an article by Zhang Xinxu a...