ERROR: Upgrade failed: DB: Duplicate entry for key 'versions_pkey'


While trying to upgrade OMP from to 3.1.2-4 I get the following error while running the database upgrade:
ERROR: Upgrade failed: DB: Duplicate entry 'plugins.generic-pdfJsViewer-1-0-0-0' for key 'versions_pkey'

Rolling back the upgrade and examining the database, I don’t see how this is caused.
SELECT * FROM omp.versions WHERE product = "pdfJsViewer";
Gives me:
1,0,0,0,“2017-08-21 15:43:27”,1,plugins.generic,pdfJsViewer,PdfJsViewerPlugin,1,0
1,0,0,0,“2017-08-23 10:41:13”,1,plugins.viewableFiles,pdfJsViewer,PdfJsViewerPlugin,1,0

product_type is different, so the key should be different. Anyone an idea what causes this error?

Hi @dersmon,

You should be able to work around this by deleting the entry with product_type = 'plugins.viewableFiles' before running the upgrade.

Alec Smecher
Public Knowledge Project Team

Thanks @asmecher, that worked, but now I have another one:

ERROR: Upgrade failed: DB: Duplicate entry '1--subjectsEnabledSubmission' for key 'press_settings_pkey'

SELECT * FROM omp.press_settings WHERE setting_name LIKE "subject%" ORDER BY setting_name ASC;

results in:


I am working on a system I have not initially setup/maintained. Any idea how these inconsistencies came to be?


Hi @dersmon,

Is it possible that an upgrade was attempted but failed, then another upgrade was attempted without first restoring from backup? When an upgrade fails, it leaves the database stuck somewhere between the two versions, and should be restored before another upgrade is attempted.

Alec Smecher
Public Knowledge Project Team

So probably the last error is the result of an already added row that the migration script tries to add a second time?

I deleted the entry for subjectsEnabledSubmission and had to delete two other rows in press_settings, now the upgrade script succeeds. After the upgrade all rows were added again, so it really seems like a bugged upgrade attempt was the error.

1 Like