MySQL时间戳默认值无效

时间:2019-01-21 15:26:32

标签: mysql wordpress phpmyadmin timestamp

我正在尝试在MYSQL 5.7.23(phpmyadmin)上创建具有默认时间戳的表

CREATE TABLE mytable(
    id MEDIUMINT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    created_at TIMESTAMP DEFAULT '1970-01-01 00:00:01',
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY(id)
);

enter image description here

1 个答案:

答案 0 :(得分:1)

TIMESTAMP值的范围从UTC的“ 1970-01-01 00:00:01”到UTC的“ 2038-01-19 03:14:07”

所以您应该使用

 created_at TIMESTAMP DEFAULT '1970-01-01 00:00:01',

或RaymondNijland的建议

created_at TIMESTAMP DEFAULT 0

或更改为

created_at datetime DEFAULT '1900-01-01 00:00:01',

https://dev.mysql.com/doc/refman/8.0/en/datetime.html