There can be only one timestamp column with current_timestamp in default or on update clause

Source: Internet
Author: User
Tags table definition

An error occurred while creating the table.

[Err] 1293-Incorrect table definition; there can be only one timestamp column with current_timestamp in default or on update clause

The creation statement is as follows:

CREATE TABLE company_news(    id              VARCHAR(32)     NOT NULL,    title           VARCHAR(50)     NOT NULL,    summary         VARCHAR(300),    content         TEXT,    company_token   VARCHAR(30)     NOT NULL,    modify_by       VARCHAR(128),    published_time  TIMESTAMP,    modify_time     TIMESTAMP       DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,    primary key(id));

Cause:

One timestamp column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both.It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column. (From the MySQL 5.5 Documentation)


This problem does not occur in MySQL 5.6,

Previusly, at most one timestamp column per table cocould be automatically initialized or updated to the current date and time.This restriction has been lifted.Any timestamp column definition can have any combination of default current_timestamp and on update current_timestamp clses. in addition, these clses now can be used with datetime column definitions. for more information, see initiic initialization and updating for Timestamp and datetime. (from the MySQL 5.6.5 Documentation)


You can consider the following solutions:

CREATE TABLE company_news(    id              VARCHAR(32)     NOT NULL,    title           VARCHAR(50)     NOT NULL,    summary         VARCHAR(300),    content         TEXT,    company_token   VARCHAR(30)     NOT NULL,    modify_by       VARCHAR(128),    published_time  TIMESTAMP       DEFAULT ‘0000-00-00 00:00:00‘,    modify_time     TIMESTAMP       DEFAULT now() ON UPDATE now(),    primary key(id));



There can be only one timestamp column with current_timestamp in default or on update clause

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.