Restore of a site XML backup fails due to duplicate entry '' for key 'unq_lwr_username' error

Still need help?

The Atlassian Community is here for you.

Ask the community


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

Restore of a site XML backup can fail due to duplicate key value violation for unique constraint "unq_lwr_username"

Environment

Confluence Data Center

Diagnosis

The following errors can be seen in the application logs located under the <Confluence_home>/logs/ folder:

For Confluence instances using MySQL database:
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: MySQLIntegrityConstraintViolationException: Duplicate entry '' for key 'unq_lwr_username' 

OR 

For Confluence instances using PostgreSQL database:
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 "unq_lwr_username" Detail: Key (lower_username)=() already exists. 

(warning) Similar errors can be reported with the MS SQL Server or Oracle databases too.

(info) Notice that the error does not indicate any value for the lower_username entry. 

(info) If you happen to see a value inside the duplicate key entry, head to the KB: Confluence site XML import fails with "duplicate key" error

Cause

Usually, this error is caused when a user entry in the USER_MAPPING  table has a value in the lower_username column as either null or the value does not match the lowercase version of their username.

Resolution

Unable to render {include} The included page could not be found.


  1. On the source Confluence database, run the following query to check which usernames have null lower_username  entry:

    SELECT * FROM user_mapping 
    WHERE 
    username IS NULL OR 
    lower_username IS NULL OR 
    lower_username != lower(username); 

    (info) Note down the usernames returned.

  2. Run the following SQL commands against your database:
    UPDATE user_mapping SET lower_username = '<lowercase_username>' WHERE username = '<username>'; 
  3. Run the SELECT statement once again to ensure the modification took effect:

    SELECT * FROM user_mapping 
    WHERE 
    username IS NULL OR 
    lower_username IS NULL OR 
    lower_username != lower(username);
  4. Restart Confluence
  5. Create a new XML backup and import on the destination server.


Last modified on Mar 6, 2025

Was this helpful?

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