Database error Error 121: "Duplicate key on write or update".

The error message "Duplicate key on write or update" in a database usually indicates that an index violates a unique constraint. This means that you are trying to insert or update a row with a value that already exists in a column with a unique index. Here are some steps you can take to fix this error:

  • Identify the table and indexThe first step is to identify the table and index that are causing the error. Look at the error message to see if it gives you any clues about the table or index that is causing the problem. You can also examine the table schema to identify any columns that have unique constraints or indexes.
  • Check for duplicate dataOnce you have identified the table and index, check if there is duplicate data in the column with the unique index. You can do this by running a query to find all rows that have the same value in the column causing the error.
  • Remove or update the duplicate dataOnce you have identified the duplicate data, you must either remove it or update it with a unique value. If the duplicate data is not needed, you can simply delete the rows with the duplicate data. If the data is needed, you can update it with a unique value, for example by appending a number to the end of the value.
  • Change the indexIf the unique index is not required, you can change the table schema and remove the index. However, if the index is necessary for data integrity, you may need to change the index to allow duplicate values or update the existing index to ensure it is unique.
  • Check for application errorsIf you have checked the database and there is no duplicate data, the error may be due to an application error. Check your code to make sure you are not accidentally trying to insert or update duplicate data.

To fix the error "Duplicate key on write or update" you need to identify the table and index causing the error, check for duplicate data, remove or update the duplicate data, change the index if necessary and check for application errors.

You don't have access to the database? #

If you do not have access to the database where the error occurs, you must contact the database administrator or the technical support team of the application using the database. Explain the error you are experiencing and provide any relevant details, such as what you were doing when the error occurred.

The database administrator or the technical support team must investigate the error and determine the cause. They may be able to fix the error themselves, for example by removing the duplicate data or changing the index. Or they may give you instructions on how to fix the error yourself, for example by changing your application code or the data you want to insert or update.

It is important to contact the database administrator or technical support to resolve the error as soon as possible, as a duplicate key error can result in data not being able to be properly stored or retrieved from the database.

Why it is not possible to fix the error without accessing the database #

When importing a database with the error "Duplicate key on write or update", the import process fails because the database engine does not allow a duplicate value to be inserted into a column with a unique index or constraint. The error indicates that there is already a record in the database with the same unique key or value as the record to be inserted, so the database engine does not allow the insertion of another record with the same key or value.

To successfully import the database, you must first identify and fix the duplicate key error before you can perform the import. This may require removing or updating the duplicate record or changing the database schema to remove the unique constraint or index.

Attempting to import a database with a double key error can corrupt the data and cause further errors in the database. It is important to fix all database errors before attempting to import or export the database to ensure that the data is properly maintained and preserved.

en_GB