Upgrading Confluence fails due to conflict with FOREIGN KEY constraint 'fk_ao_9412a1_user_app_link_user_id' error
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
Upgrading Confluence fails with an error related to a foreign key constraint
The following appears in the atlassian-confluence.log
2016-04-27 08:26:13,463 ERROR [localhost-startStop-1] [atlassian.confluence.plugin.PluginFrameworkContextListener] launchUpgrades Upgrade failed, application will not start: Upgrade task com.atlassian.confluence.upgrade.upgradetask.MsSqlServerAoUpgradeTask@1b240eb1 failed during the SCHEMA_UPGRADE phase due to: StatementCallback; SQL [ALTER TABLE AO_9412A1_USER_APP_LINK ADD CONSTRAINT fk_ao_9412a1_user_app_link_user_id FOREIGN KEY (USER_ID) references AO_9412A1_AOUSER(ID);]; The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "fk_ao_9412a1_user_app_link_user_id". The conflict occurred in database "WikiTEST", table "dbo.AO_9412A1_AOUSER", column 'ID'.; nested exception is java.sql.SQLException: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "fk_ao_9412a1_user_app_link_user_id". The conflict occurred in database "WikiTEST", table "dbo.AO_9412A1_AOUSER", column 'ID'
Cause
The conflict occurs because the constraint already exists in the database.
Workaround
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
- Rollback Confluence to pre-upgraded state.
- Back up the database.
Drop the foreign key constraint fk_ao_9412a1_user_app_link_user_id. The following query is for MySQL, please modify for any changes with the database being used.
ALTER TABLE AO_9412A1_USER_APP_LINK DROP CONSTRAINT fk_ao_9412a1_user_app_link_user_id;
- Upgrade Confluence.