If you absolutely need to set it to zeros and are aware of the implications and potential issues that might arise, then you can temporarily disable strict mode for your session, run the update statement, and then re-enable strict mode. Here's how you can do it:
-
Disable Strict Mode Temporarily:
SET @@session.sql_mode = REPLACE(@@session.sql_mode, 'NO_ZERO_DATE', ''); SET @@session.sql_mode = REPLACE(@@session.sql_mode, 'STRICT_TRANS_TABLES', '');
-
Run Your Update:
UPDATE ps_specific_price SET `from` = '0000-00-00 00:00:00' WHERE `from` is null;
-
Re-enable Strict Mode (if it was originally enabled):
SET @@session.sql_mode = CONCAT(@@session.sql_mode, ',NO_ZERO_DATE,STRICT_TRANS_TABLES');
IMPORTANT: This method temporarily disables strict mode only for your current session and doesn't affect other connections. Always be cautious about changing SQL modes, even temporarily, especially on production databases. Make sure to take a backup before making changes.
However, keep in mind that the '0000-00-00 00:00:00'
date might cause issues in some applications, libraries, or future versions of MySQL. It's often better to use a more universally recognized default date (like '1970-01-01 00:00:00'
), or to allow NULLs in the column and use NULL as the default. If you must use zeros, just be aware of the potential implications and design your application logic accordingly.