Database Upgrade Loop

After updating from 3.14.1 to 4.0.4, I seem to be stuck in a database upgrade loop. The page saying the upgrade is required says:

The following dimensions will be updated: log_link_visit_action.idaction_product_cat, log_link_visit_action.idaction_product_cat2, log_link_visit_action.idaction_product_cat3, log_link_visit_action.idaction_product_cat4, log_link_visit_action.idaction_product_cat5, log_link_visit_action.idaction_product_name, log_link_visit_action.idaction_product_sku, log_link_visit_action.product_price, log_visit.config_browser_name, log_visit.config_client_type, log_visit.location_region, log_visit.referer_name, log_visit.referer_url, log_visit.visit_total_interactions, log_visit.visitor_count_visits.

I click the “upgrade Matomo” button, and I get the following warning:

Error during plugin updates:

/home/wombatstats36/ Error trying to execute the migration ‘ALTER TABLE piwik_log_visit MODIFY COLUMN visitor_count_visits INT(11) UNSIGNED NOT NULL DEFAULT 0, MODIFY COLUMN visit_total_interactions MEDIUMINT UNSIGNED DEFAULT 0, MODIFY COLUMN referer_name VARCHAR(255) NULL, MODIFY COLUMN referer_url VARCHAR(1500) NULL, MODIFY COLUMN config_browser_name VARCHAR(40) NULL, ADD COLUMN config_client_type TINYINT( 1 ) NULL DEFAULT NULL, MODIFY COLUMN location_region char(3) DEFAULT NULL, MODIFY COLUMN location_region char(3) DEFAULT NULL;’. The error was: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘location_region’ in 'piwik_log_visit’

That same error repeats 15 times, and at the bottom of the page, there’s a link to “continue to Matomo,” but that just brings me back to the page saying a dababase upgrade is required.

I’ve checked my MySQL database, and the piwik_log_visit table exists, as does the location_region column within that table.

Edit: In case anyone else has a similar issue, this was resolved after I deleted the excess files Matomo detected after the update.