If you migrate a WordPress installation that includes WooCommerce with downloadable products those downloads will fail if the database prefix has changed. The issue stems from a constraint created by WooCommerce during the first install. The search and replace utility in Updraft Plus Pro does not fetch the constraint and thus does not change the database prefix in the foreign key.
Example:
old site: old.example.com
old db prefix: lmr_
new site: new.example.com
new db prefix: arm_
Downloading a file from the myaccount page in WooCommerce will fail with the following php error message:
Cannot add or update a child row: a foreign key constraint fails (‘new_site_db’.’arm_wc_download_log’, CONSTRAINT ‘fk_lmr_wc_download_log_permission_id’ FOREIGN KEY (‘permission_id’) REFERENCES ‘lmr_woocommerce_downloadable_product_permissions’ (‘permissio) für Abfrage INSERT INTO ‘arm_wc_download_log’ (‘timestamp’, ‘permission_id’, ‘user_id’, ‘user_ip_address’) VALUES (‘2019-02-17 11:20:32′, ’16’, ‘1’, ‘xx.xx.xx.xx’)
Solution:
The old foreign key must be droped and a new constraint must be created
ALTER TABLE ‘arm_wc_download_log’ DROP FOREIGN KEY ‘fk_lmr_wc_download_log_permission_id’;
ALTER TABLE ‘arm_wc_download_log’ ADD CONSTRAINT ‘fk_arm_wc_download_log_permission_id’ FOREIGN KEY (‘permission_id’) REFERENCES ‘arm_woocommerce_downloadable_product_permissions'(‘permission_id’) ON DELETE CASCADE ON UPDATE RESTRICT;
Feature request:
Updraft Plus Pro Migration Utility should check whether WooCommerce is included in the WordPress installation and whether the database prefix has changed between the source and target site. If both conditions are true the foreign key as explained above should be droped and the constraint recreated.
Keep up the good work. UpdraftPlus Pro is by far the best backup and migration utility on the market. Greetings to Joe.
Kind regards
Michael