How to fix “Invalid default value” MySQL error on WordPress database

Recently I wanted to duplicate a WordPress database table but I couldn’t because I got the error ERROR 1067 (42000): Invalid default value for 'post_date'.

This fix also works for other Invalid default value errors such as invalid default value for 'user_registered' and invalid default value for 'post_date_gmt'.

It took a bit of Googling but eventually I found the running the following query fixed the issue.

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

You may also find that you need to reset the timezone which can be done with:

SET time_zone = "+00:00";

I’m using Sequel Ace to manage my WordPress databases. To use this load up the database you want to change, add this query to the query tab, then press “run current”.

I should caveat this with the fact that I am not a MySQL expert. I know enough MySQL to be dangerous, so if this goes wrong it’s not my fault!

My database is running locally so if anything goes wrong I can delete it and start again. If you need to run this in production then make sure you do a database backup first and know how to restore it if something doesn’t work as expected.

How was it for you? Let me know on BlueSky or Mastodon

(Please) Link to this page

Thanks for reading. I'd really appreciate it if you'd link to this page if you mention it in your newsletter or on your blog.

Related Posts

16 Jun 2017

Fixing Theme Issues with WordPress 4.8 Media Widgets

WordPress 4.8 has just been released and, whilst not a ground breaking update, it includes some nice features that make WordPress more pleasant to use.One of the main areas focused on is some new widgets. There haven’t been any new...
26 Sep 2018

WordPress get_post_gallery() Gutenberg Polyfill

I’m working on a new WordPress theme designed for Gutenberg, however Gutenberg isn’t finished, and there are elements that won’t work until the plugin is merged with core.One such issue, that I ran into this weekend, is that get_post_gallery() doesn’t...
27 May 2013

WordPress: 10 Years Young, What Does The Future Hold?

WordPress is now 10 years old. I started using wordpress 9 years ago – which means I joined the WordPress community early on. The reason I chose WordPress is simply because of the fabled 5 minute install process – I...
01 May 2011

How To Fix WordPress and Mod Security 2

Recently my website was moved to a new web server, and in the process the server software was upgraded, and it broke some parts of my site. It took a bit of digging but in the end I worked out...
13 May 2010

6 Tips to Build Better WordPress Themes

If you want to make WordPress themes, for clients, to release for free or to sell, then there are a lot of factors you need to take into consideration. Below are some hints and tips that should help ease your...