Confluence Space import fails due to 'duplicate key value violates unique constraint' error

Still need help?

The Atlassian Community is here for you.

Ask the community

Problem

When importing a Space into Confluence, the import fails due to a duplicate key error.

The following appears in the atlassian-confluence.log file:

Import failed. Check your server logs for more information. com.atlassian.confluence.importexport.ImportExportException: Unable to complete import because the data does not match the constraints in the Confluence schema. Cause: PSQLException: ERROR: duplicate key value violates unique constraint "bandana_unique_key"

Cause

This behavior is caused by entries already existing within the Confluence database that would be duplicated by the import. 

The Confluence 'bandana' table has the following unique key constraint:

"bandana_unique_key" UNIQUE CONSTRAINT, btree (bandanacontext, bandanakey)

There are multiple possible causes for this constraint to be violated.

Workaround

  1. Follow the instructions to enable Enabling Detailed SQL Logging
  2. Attempt the Space import
  3. Stop Confluence
  4. Find the INSERT query that is causing the unique constraint violation
    • Note the banadanacontext and bandanakey values being set
  5. Delete whatever entry already exists:

    delete from BANDANA
    where BANDANACONTEXT = '<BANDANACONTEXT-value-from-insert-query>' and BANDANAKEY = '<BANDANAKEY-value-from-insert-query>';

  6. Start Confluence
  7. Attempt the Space import (repeat as needed)

 

Last modified on Aug 28, 2017

Was this helpful?

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