Column 'X' is Constrained to be UniqueError Example:An error occurred while executing connection '<connectionName>': The row with key <keyValue> could not be added to the table <tableName> due to the following error: 'Column '<columnName>' is constrained to be unique. Value '<value>' is already present.'. Note this may be an older version/variant of this error: Error reading from entity '<entityName>': Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. The column '<columnName>' in row '<rowId>' is indicating the following error: Column '<columnName>' is constrained to be unique. Value '<value>' is already present. Cause:This error is generally caused when the application is attempting to insert a value into a column that has been marked as unique, as a primary key, or an identity (depending on the source) that already has that specific value (or multiple null values). There are also some specific special cases that can lead to this error as well:
Resolution/Workaround:The General Resolution below covers the common cause for this error. Below are additional resolutions for the specific special cases mentioned in the Cause section above. General ResolutionIn most cases, the error itself lists the problematic column and value, you can use this information to go to the data source and fix the issue so that the values are now unique for that column. This may also be a symptom of other issues, like a poor choice in a primary key, especially with combo ones; truncation of values; or improperly set constraints. If there are no clear duplicate values, check the trace log to see if the values are getting changed in the sync process and check the combination keys are actually unique and that the columns that should be unique are set properly. 'FilePath' is Constrained to be UniqueIf the column in the error is 'FilePath' and you are syncing to SharePoint, see this specific article about that issue: Failed to Enable Constraints - 'FilePath' is Constrained to be Unique Primary Key Column is also Query Join ColumnYou cannot do this - you need to use either another primary key or a different value to join tables in the query. Using Dynamic Column as Primary KeyYou cannot do this as this column type is variable and may not be unique over time - you must select another non-Dynamic Column as the primary key. Using Updatable View for QueryThe view will inherit any constraints from the original table(s), so you still must follow those when writing values via the view back to the tables in SQL. You may have to change your query if you expected the column to be non-unique when used in the view. Using Date/Time-Type Fields as Primary KeyTimestamps are not always unique so you may get this if you are using date or date/time columns as the key or as part of a combination key. There are also some additional errors that can occur from this, so it is not supported to use Date/Time fields as the primary key. You need to change the defined primary key to not use Date/Time columns. Additional Error Text VariationsFor a variation on this error specifically addressing custom primary key constraint errors, see Error Reading Back Keys Because Table 'X' No Longer Has a Primary Key Defined. There is also this Key-specific variation of the error, The Primary Key 'X' is Not Unique. |