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

后端 未结 19 960
没有蜡笔的小新
没有蜡笔的小新 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:54

    This is incredibly ugly, but it also fixed the problem quickly for me. Your table needs a unique key which you will use to fix the tainted columns. In this example, the primary key is called 'id' and the broken timestamp column is called 'BadColumn'.

    1. Select the IDs of the tainted columns.

      select id from table where BadColumn='0000-00-00 00:00:00'

    2. Collect the IDs into a comma-delimited string. Example: 1, 22, 33. I used an external wrapper for this (a Perl script) to quickly spit them all out.

    3. Use your list of IDs to update the old columns with a valid date (1971 through 2038).

      update table set BadColumn='2000-01-01 00:00:00' where id in (1, 22, 33)

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