Upgrade Fails Due to Foreign Key Constraint in the PAGETEMPLATES Table
Upgrade fails. The following appears in the
Cannot add or update a child row: a foreign key constraint fails (`confluencedb/#sql-214_69ba`, CONSTRAINT `FKBC7CE96A17D4A070` FOREIGN KEY (`PREVVER`) REFERENCES `pagetemplates` (`TEMPLATEID`))
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.
Always backup your data before performing any modifications to the database.
Roll back database to the previous state (before upgrade)
Search for the rogue row by running:
select * from pagetemplates where prevver not in (select templateid from pagetemplates);
Delete it after making a backup of your database:
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:
delete from pagetemplates where templateid = <template_id>;
<template_id> is the value for templateid returned from the select query.
- Re-run the upgrade