Title: Cannot add foreign key constraint database errors
Last modified: November 4, 2018

---

# Cannot add foreign key constraint database errors

 *  Resolved [Ambyomoron](https://wordpress.org/support/users/josiah-s-carberry/)
 * (@josiah-s-carberry)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/cannot-add-foreign-key-constraint-database-errors/)
 * Using ver. 2.2.1 of plugin.
 * In the course of enabling maintenance mode a series of errors were logged in 
   the web server error log. As I saw no errors in the backend itself I do not know
   exactly what triggered it. However, this is what I do:
    1. Under Modules | Start
   date I click on Now, then Done 2. I set the countdown to 1 minute 3. I click 
   on Save settings 4. Under General | Status I click on Activated 5. I click on
   Save settings 6. About 1 minute later Under General | Status I click on Deactivated
   7. I click on Save settings
 * By the IP address in the errors, it is clear that they are related to the above
   actions.
 * 10:47:14.771491
    stderr: PHP message: WordPress database error Cannot add foreign
   key constraint for query , referer: [https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode](https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode)
 * 10:47:14.771599
    stderr: \t\t\t\t\tALTER TABLE `cccwp_wc_download_log`, referer:
   [https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode](https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode)
 * 10:47:14.771604
    stderr: \t\t\t\t\tADD CONSTRAINT `fk_wc_download_log_permission_id`,
   referer: [https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode](https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode)
 * 10:47:14.771609
    stderr: \t\t\t\t\tREFERENCES `cccwp_woocommerce_downloadable_product_permissions`(`
   permission_id`) ON DELETE CASCADE;, referer: [https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode](https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode)
 * 10:47:14.771612
    stderr: \t\t\t\t made by require_once(‘wp-admin/admin.php’),
   require_once(‘wp-load.php’), require_once(‘blahblah/wp-config.php’), require_once(‘
   wp-settings.php’), do_action(‘init’), WP_Hook->do_action, WP_Hook->apply_filters,
   WC_Install::check_version, WC_Install::install, WC_Install::create_tables, referer:
   [https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode](https://mysite.com/wp-admin/options-general.php?page=wp-maintenance-mode)
 * I note further the following two entries in the web server access log, that may
   or may not be related:
 * From the web server:
    POST /wp-admin/admin-ajax.php?action=wp_1_wc_privacy_cleanup&
   nonce=925520a95c HTTP/1.1
 * From the admin client (same as the errors above):
    POST /?wc-ajax=get_refreshed_fragments
   HTTP/2.0

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [George J](https://wordpress.org/support/users/georgejipa/)
 * (@georgejipa)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/cannot-add-foreign-key-constraint-database-errors/#post-10846832)
 * Hello [@josiah-s-carberry](https://wordpress.org/support/users/josiah-s-carberry/),
 * All that errors are related to Woocommerce. I suggest opening a ticket on their
   support forum: [https://wordpress.org/support/plugin/woocommerce](https://wordpress.org/support/plugin/woocommerce).
 * —
    George
 *  Thread Starter [Ambyomoron](https://wordpress.org/support/users/josiah-s-carberry/)
 * (@josiah-s-carberry)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/cannot-add-foreign-key-constraint-database-errors/#post-10846912)
 * Thank you for this feedback, George. I will be sure to raise the issue with WooCommerce.
 * I wonder, though, if you would be so kind as to help me understand how such an
   error could occur when I am on the WP Maintenance Mode settings page?
 *  [George J](https://wordpress.org/support/users/georgejipa/)
 * (@georgejipa)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/cannot-add-foreign-key-constraint-database-errors/#post-10846954)
 * [@josiah-s-carberry](https://wordpress.org/support/users/josiah-s-carberry/) 
   Because Woocommerce is running (in the background) on all pages you access. Including
   on WP MM settings page.
 *  [George J](https://wordpress.org/support/users/georgejipa/)
 * (@georgejipa)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/cannot-add-foreign-key-constraint-database-errors/#post-10857984)
 * [@josiah-s-carberry](https://wordpress.org/support/users/josiah-s-carberry/) 
   As far as I see, your problem is solved. So, please set the status to **Resolved**.
 * [https://wordpress.org/support/topic/error-during-alter-table-wp_wc_download_log/](https://wordpress.org/support/topic/error-during-alter-table-wp_wc_download_log/)
 *  Thread Starter [Ambyomoron](https://wordpress.org/support/users/josiah-s-carberry/)
 * (@josiah-s-carberry)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/cannot-add-foreign-key-constraint-database-errors/#post-10858003)
 * It had to do with an upgrade, where changes to the database were done in the 
   background. I suppose I was turning off maintenance mode when the error occurred,
   thus the reference to this plugin.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Cannot add foreign key constraint database errors’ is closed to new replies.

 * ![](https://ps.w.org/wp-maintenance-mode/assets/icon-256x256.gif?rev=3027645)
 * [LightStart - Maintenance Mode, Coming Soon and Landing Page Builder](https://wordpress.org/plugins/wp-maintenance-mode/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-maintenance-mode/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-maintenance-mode/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-maintenance-mode/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-maintenance-mode/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-maintenance-mode/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Ambyomoron](https://wordpress.org/support/users/josiah-s-carberry/)
 * Last activity: [7 years, 7 months ago](https://wordpress.org/support/topic/cannot-add-foreign-key-constraint-database-errors/#post-10858003)
 * Status: resolved