Upgrade Fails Due to Foreign Key Constraint in the PAGETEMPLATES Table

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

Upgrade fails. The following appears in the atlassian-confluence.log:

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 backup your data before performing any modifications to the database.

  1. Roll back database to the previous state (before upgrade)

  2. Search for the rogue row by running:

    select * from pagetemplates where prevver not in (select templateid from pagetemplates);
    
  3. 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));

    tip/resting Created with Sketch.

    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.

  4. Re-run the upgrade
Last modified on Nov 14, 2018

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.