Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaorukobo/718f4eb684ac01e1b65fc4cb69587fae to your computer and use it in GitHub Desktop.
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
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';
@arctic-blue
Copy link

wonderfull! Thanks a lot!!

@RetroGameTalk
Copy link

very nice thanks!

@asifulmamun
Copy link

asifulmamun commented Jan 24, 2025

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';

@kaorukobo
Copy link
Author

@asifulmamun Any difference from line 1: SET SQL_MODE = '';?

@asifulmamun
Copy link

asifulmamun commented Jan 25, 2025

@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