Unable to create or change a table without a primary key
-
We have error in logs:
WordPress database error Unable to create or change a table without a primary key when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication so please consult your DBA before changing this setting. for query
Solution:
Modify install.php file:
$sql = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "gr_orders_map ( <code>id</code> bigint(20) unsigned NOT NULL AUTO_INCREMENT, <code>store_id</code> varchar(16) NOT NULL DEFAULT '', <code>gr_order_id</code> varchar(16) NOT NULL DEFAULT '', <code>woocommerce_order_id</code> bigint(20) unsigned NOT NULL, PRIMARY KEY (<code>id</code>), UNIQUE KEY <code>store_id</code> (<code>store_id</code>,<code>gr_order_id</code>), KEY <code>woocommerce_order_id</code> (<code>woocommerce_order_id</code>) )" . $charset_collate; dbDelta( $sql ); $sql = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "gr_products_map ( <code>id</code> bigint(20) unsigned NOT NULL AUTO_INCREMENT, <code>store_id</code> varchar(16) NOT NULL DEFAULT '', <code>gr_product_id</code> varchar(16) NOT NULL DEFAULT '', <code>woocommerce_product_id</code> bigint(20) unsigned NOT NULL, PRIMARY KEY (<code>id</code>), UNIQUE KEY <code>store_id</code> (<code>store_id</code>,<code>gr_product_id</code>), KEY <code>woocommerce_product_id</code> (<code>woocommerce_product_id</code>) ) " . $charset_collate; dbDelta( $sql ); $sql = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "gr_variants_map ( <code>id</code> bigint(20) unsigned NOT NULL AUTO_INCREMENT, <code>store_id</code> varchar(16) NOT NULL DEFAULT '', <code>woocommerce_variant_id</code> bigint(20) NOT NULL, <code>gr_variant_id</code> varchar(16) NOT NULL DEFAULT '', PRIMARY KEY (<code>id</code>), UNIQUE KEY <code>store_id</code> (<code>store_id</code>,<code>woocommerce_variant_id</code>), KEY <code>gr_variant_id</code> (<code>gr_variant_id</code>) ) " . $charset_collate; dbDelta( $sql ); $sql = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "gr_schedule_jobs_queue ( <code>id</code> bigint(20) unsigned NOT NULL AUTO_INCREMENT, <code>customer_id</code> varchar(8) DEFAULT NULL, <code>type</code> varchar(16) DEFAULT NULL, <code>payload</code> text, <code>created_at</code> timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (<code>id</code>) ) " . $charset_collate; dbDelta( $sql ); $sql = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "gr_configuration ( <code>id</code> bigint(20) unsigned NOT NULL AUTO_INCREMENT, <code>name</code> varchar(32) NOT NULL DEFAULT '', <code>value</code> text, PRIMARY KEY (<code>id</code>), UNIQUE KEY <code>name</code> (<code>name</code>) )" . $charset_collate; dbDelta( $sql );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Unable to create or change a table without a primary key’ is closed to new replies.