From 08d301779bd159679f0f6211a057f413dd92e31c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 9 Jul 2019 17:59:16 -0300 Subject: [PATCH] Set max index length for slug in tax class table --- includes/class-wc-install.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index 5a7f9d4cc95..45b9e2b0055 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -703,6 +703,13 @@ class WC_Install { $collate = $wpdb->get_charset_collate(); } + /* + * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that. + * As of WP 4.2, however, they moved to utf8mb4, which uses 4 bytes per character. This means that an index which + * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters. + */ + $max_index_length = 191; + $tables = " CREATE TABLE {$wpdb->prefix}woocommerce_sessions ( session_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, @@ -903,7 +910,7 @@ CREATE TABLE {$wpdb->prefix}wc_tax_rate_classes ( name varchar(200) NOT NULL DEFAULT '', slug varchar(200) NOT NULL DEFAULT '', PRIMARY KEY (tax_rate_class_id), - UNIQUE KEY slug (slug) + UNIQUE KEY slug (slug($max_index_length)) ) $collate; ";