Invalid default value for 'dateAdded'

前端 未结 8 940
野性不改
野性不改 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:30

    CURRENT_TIMESTAMP is version specific and is now allowed for DATETIME columns as of version 5.6.

    See MySQL docs.

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

    Change the type from datetime to timestamp and it will work! I had the same issue for mysql 5.5.56-MariaDB - MariaDB Server Hope it can help... sorry if depricated

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

    mysql version 5.5 set datetime default value as CURRENT_TIMESTAMP will be report error you can update to version 5.6 , it set datetime default value as CURRENT_TIMESTAMP

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

    I had the same issue, following fix solved my problem.

    • Select Type as 'TIMESTAMP'

    • DON'T ENTER ANYTHING IN LENGTH/VALUES FIELD. KEEP IT BLANK

    • Select CURRENT_TIMESTAMP as Default value.

    I am using MySQL ver 5.5.56

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

    I solved mine by changing DATE to DATETIME

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

    Also do note when specifying DATETIME as DATETIME(3) or like on MySQL 5.7.x, you also have to add the same value for CURRENT_TIMESTAMP(3). If not it will keep throwing 'Invalid default value'.

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