Violation of Primary Key Constraint Error

  • Updated

When adding content, a user, a menu, taxonomy, or any other item in the workarea or via the API an error stating, "Violation of PRIMARY KEY constraint "column_name". Cannont insert duplicate key in object 'object_name'" occurs. 

Before running any scripts listed below, please make a backup of your existing database.

This type of PK issue is caused by the maxentries table going beyond its set value of max entries allowed. 

To resolve this issue, run a SQL script against the database. 

  1. Identify the Ektron version you are using by using this KB: Retrieve Version Information.
  2. Download the corresponding MaxEntries script.

    8.02 - 8.02SP5MaxEntries for 8_02SPX versions
    8.5 - 8.5SP3MaxEntries Script for 8_5 versions
    8.6.0 - 8.6.1
    MaxEntries Script for 8_6 and 8_6SP1
    8.7 - 8.7SP2
    MaxEntries Script for 8_7 versions
    9.0 - 9.4
    MaxEntries Script for 9_x versions

  3. Unzip the downloaded file.
  4. Create a backup of your database.
  5. Execute the MaxEntries script.
  6. Re-test the behavior.

Legacy versions of the product have a less automated method for updating the max entries table.

1) Run the following script after replacing 'task_history_note'  with the table that is being referenced in the error. Note the number returned by it.

select max_table_number 
from max_entries 
where table_name = 'task_history_note' 

2) Run the following script and note the number returned. If this script returns a number lower than the first script returns then you have confirmed that the limit is too low on your side as well. 

select * from task_history_note order by entry_id desc 

3) Replace correctMaxEntriesLimit with the value returned by step 2, but one higher. So if 2 returned 20000 then correctMaxEntriesLimit should be 20001. 

update max_entries 
set max_table_number = correctMaxEntriesLimit 
where table_name = 'task_history_note'