December 23, 2023

Fixing the “Key Column ‘option_id’ Doesn’t Exist in Table” (Wordpress)


Database errors can be frustrating, especially when you’re working on optimizing your database for high-performance operations. One common error that users encounter is the “Key column ‘option_id’ doesn’t exist in table.” In this guide, we’ll address this specific error and walk you through the steps to resolve it.

This one was really hard, as I noticed a lot of CPU spikes and error logs. I noticed this error:

023-12-23 00:39:51.980 [STDERR] WordPress database error Unknown column 'option_id' in 'order clause' for query SELECT * FROM wp_options WHERE option_name LIKE 'wp\_1\_wc\_privacy\_cleanup\_batch\_%' ORDER BY option_id ASC LIMIT 1 made by do_action('wp_ajax_nopriv_wp_1_wc_privacy_cleanup'), WP_Hook-&gt;do_action, WP_Hook-&gt;apply_filters, WP_Background_Process-&gt;maybe_handle, WC_Background_Process-&gt;handle, WC_Background_Process-&gt;get_batch<br>PHP Warning: Attempt to read property "option_name" on null in /usr/local/lsws/wordpress/wp-content/plugins/woocommerce/includes/abstracts/class-wc-background-process.php on line 74<br>PHP Warning: Attempt to read property "option_value" on null in /usr/local/lsws/wordpress/wp-content/plugins/woocommerce/includes/abstracts/class-wc-background-process.php on line 75<br>2023-12-23 00:39:51.980 [STDERR] WordPress database error Unknown column 'option_id' in 'order clause' for query<br>SELECT *<br>FROM wp_options<br>WHERE option_name LIKE 'elementor\_1\_elementor\_pro\_updater\_batch\_%'<br>ORDER BY option_id ASC<br>LIMIT 1<br>made by do_action('wp_ajax_elementor_1_elementor_pro_updater'), WP_Hook-&gt;do_action, WP_Hook-&gt;apply_filters, Elementor\Core\Base\BackgroundProcess\WP_Background_Process-&gt;maybe_handle, Elementor\Core\Base\Background_Task-&gt;handle, Elementor\Core\Base\Background_Task-&gt;get_batch, Elementor\Core\Base\BackgroundProcess\WP_Background_Process-&gt;get_batch

User Scenario:

Two months ago, user Resolvedwritermuhammadzakaullah (@writermuhammadzakaullah) posted a question on a forum, seeking help for an error message. Here’s what the user experienced:

“Hi, I get the following error when trying to activate high-performance keys or revert them on some tables: Key column ‘option_id’ doesn’t exist in table I have uploaded diagnostic data via the id YrQ6U9cu Please help me.”

In response to this query, we will use the same approach detailed in the previous article to help Resolvedwritermuhammadzakaullah and others facing this issue.

Step 1: Accessing Your Database:

To start, you’ll need access to your MariaDB database. You can use the MariaDB command-line client or a web interface like PHPMyAdmin. We’ll cover both methods.

Using MariaDB Command-Line Client:

  1. Open a terminal or SSH into your serer: Log in to your database using the following command, replacing your_username with your database username:cssemysql -u your_username -p
  2. Enter your database password when prompted.

Using PHPMyAdmin:

  1. Access your PHPMyAdmin web interface and log in with your database credentials.

Step 2: Run the SQL Command:

Now that you’re connected to your database, it’s time to resolve the “Key column ‘option_id’ doesn’t exist in table” error. In this example, we want to add a unique key to the option_id column in the affected table to rectify the situation.

Using MariaDB Command-Line Client:

ALTER TABLE your_table_name ADD COLUMN option_id INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD UNIQUE KEY option_id(option_id);

This command adds a new column named option_id with unique values to the specified table.

Using PHPMyAdmin:

  1. Select the database containing the affected table.
  2. Click on the table to select it.
  3. Navigate to the SQL tab or similar functionality.
  4. Paste the following SQL command and click “Go” or “Execute”:
    ALTER TABLE your_table_name ADD COLUMN option_id INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD UNIQUE KEY option_id(option_id);

Step 3: Verify the Changes:

After executing the SQL command, you should receive a confirmation message that the operation was successful.

Conclusion:

Database errors can be challenging, but with the right guidance, they can be resolved efficiently. By following the steps outlined in this guide, you can address the “Key column ‘option_id’ doesn’t exist in table” error in MariaDB and ensure your database is structured correctly for high-performance operations.

As always, remember to back up your data before making any modifications to your database. If you encounter other database challenges or have further questions, seek assistance from the database community or professionals.

We hope this guide has been helpful in resolving the specific error reported by Resolvedwritermuhammadzakaullah and that it assists you in your database management efforts.

Share this post:
Facebook
Twitter
LinkedIn
WhatsApp

Discover more articles