MySQL Incorrect datetime value: '0000-00-00 00:00:00'

后端 未结 19 1003
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 15:51

I\'ve recently taken over an old project that was created 10 years ago. It uses MySQL 5.1.

Among other things, I need to change the default character set from latin1

19条回答
  •  自闭症患者
    2020-11-29 16:32

    I wasn't able to do this:

    UPDATE users SET created = NULL WHERE created = '0000-00-00 00:00:00'
    

    (on MySQL 5.7.13).

    I kept getting the Incorrect datetime value: '0000-00-00 00:00:00' error.

    Strangely, this worked: SELECT * FROM users WHERE created = '0000-00-00 00:00:00'. I have no idea why the former fails and the latter works... maybe a MySQL bug?

    At any case, this UPDATE query worked:

    UPDATE users SET created = NULL WHERE CAST(created AS CHAR(20)) = '0000-00-00 00:00:00'
    

提交回复
热议问题