MySQL can only have one column is the timestamp problem

Source: Internet
Author: User

MySQL Error "There can be is only one TIMESTAMP column with current_timestamp in DEFAULT clause" even though I ' m doing nothin G wrong

http://jasonbos.co/two-timestamp-columns-in-mysql/


This is a very common table: There are create_time, update_time, even can be said to be normative, of course we would like these times to automatically update, to MySQL processing, but the problem came:

Create a table such as:

CREATE TABLE ' test_table ' (' ID ' INT () not NULL, ' created_at ' TIMESTAMP not null DEFAULT current_timestamp, ' updated_at ') TIMESTAMP not NULL DEFAULT current_timestamp on UPDATE current_timestamp) ENGINE = INNODB;

The original MySQL will automatically process:

CREATE TABLE ' test_table ' (' ID ' INT () not NULL, ' created_at ' TIMESTAMP not NULL for DEFAULT 0, ' updated_at ' TIMESTAMP not NU LL DEFAULT current_timestamp on UPDATE current_timestamp) ENGINE = INNODB;
INSERT into test_table (ID, created_at, updated_at) VALUES (1, NULL, NULL);

Has fun ...

MySQL can only have one column is the timestamp problem

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.