Upgrade Fails Due to Foreign Key Constraint in the PAGETEMPLATES Table
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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
Symptoms
Upgrade fails. The following appears in the atlassian-confluence.log
:
1
Cannot add or update a child row: a foreign key constraint fails (`confluencedb/#sql-214_69ba`, CONSTRAINT `FKBC7CE96A17D4A070` FOREIGN KEY (`PREVVER`) REFERENCES `pagetemplates` (`TEMPLATEID`))
Cause
It means there is a row in the PAGETEMPLATES
table where its prevver
column does not exist in the templateid
column. This is a constraint violation.
Resolution
Always back up your data before making any database modifications. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
Roll back database to the previous state (before upgrade)
Search for the rogue row by running:
1
select * from pagetemplates where prevver not in (select templateid from pagetemplates);
Delete it after making a backup of your database:
1
delete from pagetemplates where templateid is in (select templateid from pagetemplates where prevver not in (select templateid from pagetemplates));
If you are using MySQL, the delete command above will fail. The work around is to delete the problematic template one by one:
1
delete from pagetemplates where templateid = <template_id>;
<template_id> is the value for templateid returned from the select query.
Re-run the upgrade
Was this helpful?