Invalid default value for 'create_date' timestamp field

后端 未结 16 1547
我寻月下人不归
我寻月下人不归 2020-11-30 16:49

I have the following sql create statement

mysql> CREATE  TABLE IF NOT EXISTS `erp`.`je_menus` (
    ->   `id` INT(11) NOT NULL AUTO_INCREMENT ,
    -&g         


        
16条回答
  •  情深已故
    2020-11-30 17:19

    TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC (see doc). The default value must be within that range.

    Other odd, related, behavior:

    CREATE TABLE tbl1 (
        ts TIMESTAMP);  
    Query OK, 0 rows affected (0.01 sec)
    
    CREATE TABLE tbl2 (
        ts TIMESTAMP,
        ts2 TIMESTAMP);
    ERROR 1067 (42000): Invalid default value for 'ts2'
    
    CREATE TABLE tbl3 (
        ts TIMESTAMP,
        ts2 TIMESTAMP DEFAULT '1970-01-01 00:00:01');
    Query OK, 0 rows affected (0.01 sec)
    

    Side note, if you want to insert NULLS:

    CREATE TABLE tbl4 (
        ts TIMESTAMP NULL DEFAULT NULL);
    

提交回复
热议问题