Created
March 12, 2020 03:13
-
-
Save kaorukobo/718f4eb684ac01e1b65fc4cb69587fae to your computer and use it in GitHub Desktop.
How to solve the `invalid default value for 'post_date'` error on WordPress DB with MySQL when modifying the schema of wp_posts table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET SQL_MODE = ''; | |
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'; | |
ALTER TABLE `wp_posts` CHANGE `post_date_gmt` `post_date_gmt` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'; | |
ALTER TABLE `wp_posts` CHANGE `post_modified` `post_modified` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'; | |
ALTER TABLE `wp_posts` CHANGE `post_modified_gmt` `post_modified_gmt` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00'; |
Sometimes first remove MySQL strict mode before the alter tables,
Check if strict mode is enabled:
SELECT @@GLOBAL.sql_mode;
Disable strict mode:
SET GLOBAL sql_mode = '';
Alter:
ALTER TABLE `wp_posts` CHANGE `post_date` `post_date` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00';
ALTER TABLE `wp_posts` CHANGE `post_date_gmt` `post_date_gmt` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00';
ALTER TABLE `wp_posts` CHANGE `post_modified` `post_modified` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00';
ALTER TABLE `wp_posts` CHANGE `post_modified_gmt` `post_modified_gmt` DATETIME NOT NULL DEFAULT '1970-01-01 00:00:00';
After altering table: (re-enable strict mode)
SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES';
@asifulmamun Any difference from line 1: SET SQL_MODE = '';
?
@asifulmamun Any difference from line 1:
SET SQL_MODE = '';
?
@kaorukobo
Ohh sorry, I didn't see before carefully
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very nice thanks!