Solved! “Uncaught RuntimeException: Error saving action: Error saving action: Database error.” … “ActionScheduler_DBStoreMigrator.php”
I have been having issues with a Woocommerce installation, where I received an error like this:
Fatal error: Uncaught RuntimeException: Error saving action: Error saving action: Database error. in
scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php:44 Stack trace: #0 /home/clickna8/public_html/website.com/wp-
ActionScheduler_DBStoreMigrator->save_action(Object(ActionScheduler_Action), NULL) #1 /home/clickna8/public_html/website.com/wp-
>save_action(Object(ActionScheduler_Action)) #2 /home/clickna8/public_html/website.com/wp-content/plugins/woocommerce/packages/action-
scheduler/classes/ActionScheduler_ActionFactory.php(84): ActionScheduler_ActionFactory->store(Object(ActionScheduler_Action)) #3
/home/clickna8/public_html/website.com/wp-content/plugins/woocommerce/packages/action-schedu in /home/clickna8/public_html/website.com/wp-
content/plugins/woocommerce/packages/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php on line 44
The issue also presented itself in the form of a massive
wp_actionscheduler_logs table. Like, 1000s of entries every few seconds, crashing my hosting setup and ruining many a day of my life.
Searching the web on this one was unhelpful, but I figured it out myself. The problem was that the site was built with a staging environment, and when it was transferred back the database got kerfuffled. Straight up corrupted.
So, via phpMyAdmin, I had to go in and correct everything manually. Here’s how to do that.
The Database Tables in Question
There are four tables we want to check. They all start with (typically)
wp_ but may be a bit different depending on who and how your WordPress installation as setup. But they all have
_actionscheduler_ in the name.
Deleting the Existing Data
So, firstly, the issue is very likely that the data in the tables is corrupt, specifically in that the primary key column has a bunch of 0s. If you click on the Browse link next to one of them, say
wp_actionscheduler_actions, and there’s a column with a bunch of 0s in it, that’s no good.
To empty the data from a column:
- Backup your database. You’re already in phpMyAdmin so there’s really no excuse not to do so.
- Deactivate Woocommerce. You don’t want it to try and create new ones while you’re trying to empty out the old ones.
Emptynext to the table in phpMyAdmin, the last button shown in this screenshot:
This is important. Without this, and as long as there are all zeros in those columns, we cannot proceed!
Correct Indexes, Auto-increments and Primary Keys
Once all four tables have been emptied, we need to get them setup correctly. For each of them, we’ll need to click on Structure next to their entry:
Each table’s structure has to be setup correctly in order for Woocommerce to add new entries. Here is the correct structure for the
Chances are, yours won’t have those gold and silver keys next to the table names, nor will one of them read in the Extras column.
If you didn’t have the columns of zeros in any of the tables, and your gold / silver keys and AUTO_INCREMENT are all set, then what we’re addressing in this post is likely not the issue for you.
So how do we get all of those icons?
To get a grey key next to a table, we need to set it to “index”. To do that, you click this link to the right of it:
Do that with all of the columns that require it, based on the screenshots of which tables need which structures below.
To get the gold key, aka setting that column as “primary” you click the gold key icon / link next to it:
Finally, to make sure we have the “Extras” column set to AUTO_INCREMENT, we need to click this Change link next to the column with the gold key / primary:
You’ll see an interface like this:
Check this A_I box:
Click Save and you should be good to go. If a pink box comes up stating something about how you can’t change it because of duplicate keys, you need to empty that table again as outlined above, and you probably didn’t disable Woocommerce.
Do this for each of the four tables.
Proper Settings for Each Action Scheduler Table