Invalid default value for 'dateAdded'

前端 未结 8 941
野性不改
野性不改 2020-11-27 15:17

I got a stupid problem with SQL that I can\'t fix.

ALTER TABLE  `news` 
 ADD  `dateAdded` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP AUTO_INCREMENT ,
 ADD PRIMARY         


        
相关标签:
8条回答
  • 2020-11-27 15:55

    I have mysql version 5.6.27 on my LEMP and CURRENT_TIMESTAMP as default value works fine.

    0 讨论(0)
  • 2020-11-27 15:57

    CURRENT_TIMESTAMP is only acceptable on TIMESTAMP fields. DATETIME fields must be left either with a null default value, or no default value at all - default values must be a constant value, not the result of an expression.

    relevant docs: http://dev.mysql.com/doc/refman/5.0/en/data-type-defaults.html

    You can work around this by setting a post-insert trigger on the table to fill in a "now" value on any new records.

    0 讨论(0)
提交回复
热议问题