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

后端 未结 19 1019
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  Happy的楠姐
    2020-11-29 16:32

    I have this error as well after upgrading MySQL from 5.6 to 5.7

    I figured out that the best solution for me was to combine some of the solutions here and make something of it that worked with the minimum of input.

    I use MyPHPAdmin for the simplicity of sending the queries through the interface because then I can check the structure and all that easily. You might use ssh directly or some other interface. The method should be similar or same anyway.

    ...

    1.

    First check out the actual error when trying to repair the db:

    joomla.jos_menu Note : TIME/TIMESTAMP/DATETIME columns of old format have been upgraded to the new format.

    Warning : Incorrect datetime value: '0000-00-00 00:00:00' for column 'checked_out_time' at row 1

    Error : Invalid default value for 'checked_out_time'

    status : Operation failed

    This tells me the column checked_out_time in the table jos_menu needs to have all bad dates fixed as well as the "default" changed.

    ...

    2.

    I run the SQL query based on the info in the error message:

    UPDATE jos_menu SET checked_out_time = '1970-01-01 08:00:00' WHERE checked_out_time = 0
    

    If you get an error you can use the below query instead that seems to always work:

    UPDATE jos_menu SET checked_out_time = '1970-01-01 08:00:00' WHERE CAST(checked_out_time AS CHAR(20)) = '0000-00-00 00:00:00'
    

    ...

    3.

    Then once that is done I run the second SQL query:

    ALTER TABLE `jos_menu` CHANGE `checked_out_time` `checked_out_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP;
    

    Or in the case it is a date that has to be NULL

    ALTER TABLE `jos_menu` CHANGE `checked_out_time` `checked_out_time` DATETIME NULL DEFAULT NULL;
    

    ...

    If I run repair database now I get:

    joomla.jos_menu OK

    ...

    Works just fine :)

提交回复
热议问题