Commit 5654c5f50f4 for woocommerce
commit 5654c5f50f4942f68eab6d89edccf259103e286f
Author: Brandon Kraft <public@brandonkraft.com>
Date: Sun Apr 19 00:02:35 2026 -0500
Suppress harmless dbDelta duplicate key errors during table creation (#64188)
* Suppress harmless dbDelta errors during table creation
Use $wpdb->suppress_errors() around the dbDelta() call in
create_tables() to prevent "Multiple primary key defined" and
"Duplicate key name" MySQL errors from being logged during
WooCommerce updates. These are benign errors caused by dbDelta
attempting to ADD indexes that already exist, a known WordPress
core limitation (core ticket #34870). Genuine missing-table
failures are caught by verify_base_tables() which runs immediately
after create_tables().
Follows the existing pattern in DatabaseUtil::get_missing_tables().
* chore: Add changelog entry for dbDelta error suppression fix
* Rename $suppress to $suppress_errors for consistency with DatabaseUtil
diff --git a/plugins/woocommerce/changelog/63962-fix-dbdelta-duplicate-key-errors b/plugins/woocommerce/changelog/63962-fix-dbdelta-duplicate-key-errors
new file mode 100644
index 00000000000..e7cf1201d66
--- /dev/null
+++ b/plugins/woocommerce/changelog/63962-fix-dbdelta-duplicate-key-errors
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Suppress harmless duplicate key database errors logged during WooCommerce table creation on update.
diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php
index 208637a793a..8a489899019 100644
--- a/plugins/woocommerce/includes/class-wc-install.php
+++ b/plugins/woocommerce/includes/class-wc-install.php
@@ -1835,7 +1835,9 @@ class WC_Install {
}
}
+ $suppress_errors = $wpdb->suppress_errors( true );
$db_delta_result = dbDelta( self::get_schema() );
+ $wpdb->suppress_errors( $suppress_errors );
$comment_type_index_exists = $wpdb->get_row( "SHOW INDEX FROM {$wpdb->comments} WHERE key_name = 'woo_idx_comment_type'" );
if ( null === $comment_type_index_exists ) {