{"id":2826,"date":"2026-02-19T11:48:00","date_gmt":"2026-02-19T11:48:00","guid":{"rendered":"https:\/\/hauweele.net\/~gawen\/blog\/?p=2826"},"modified":"2026-02-19T11:48:00","modified_gmt":"2026-02-19T11:48:00","slug":"error-500-in-nextcloud-polls","status":"publish","type":"post","link":"https:\/\/hauweele.net\/~gawen\/blog\/?p=2826","title":{"rendered":"Error 500 in nextcloud polls"},"content":{"rendered":"<p>Today we found the poll application on one of our nextcloud instance to be completely broken. Attempting to create a new poll or add date options to an existing one resulted in HTTP 500 errors. In nextcloud logs, there were errors like:<\/p>\n<pre>\r\nduplicate key value violates unique constraint \"oc_polls_polls_pkey\"\r\nDETAIL: Key (id)=(9) already exists.\r\n<\/pre>\n<p>or when adding options to an existing poll:<\/p>\n<pre>\r\nOCP\\AppFramework\\Db\\DoesNotExistException: Did expect one result but found none\r\n<\/pre>\n<p>As a clue, this happened after a migration of the nextcloud DB from MySQL to PostgreSQL. My guess is that the PostgreSQL sequences were not updated correctly during the migration. So it was not possible to create either new rows for options in a poll or even a poll itself after a certain point, when the auto generated ID conflicted with an existing ID in the tables, which is the unique constraint violation you see in the error.<\/p>\n<p>So the behavior was, we could add some options and some polls, but as soon as the sequence catches up to an existing ID, any INSERT fails with a primary key conflict. In our case only the polls tables seemed to be affected, but this could happen on other tables too because of the migration.<\/p>\n<p>The fix was to reset the sequences to the current maximum ID for each table of the polls application:<\/p>\n<pre>\r\nSELECT setval('oc_polls_polls_id_seq',    (SELECT MAX(id) FROM oc_polls_polls));\r\nSELECT setval('oc_polls_options_id_seq',  (SELECT MAX(id) FROM oc_polls_options));\r\nSELECT setval('oc_polls_votes_id_seq',    (SELECT MAX(id) FROM oc_polls_votes));\r\nSELECT setval('oc_polls_share_id_seq',    (SELECT MAX(id) FROM oc_polls_share));\r\nSELECT setval('oc_polls_comments_id_seq', (SELECT MAX(id) FROM oc_polls_comments));\r\nSELECT setval('oc_polls_log_id_seq',      (SELECT MAX(id) FROM oc_polls_log));\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today we found the poll application on one of our nextcloud instance to be completely broken. Attempting to create a new poll or add date options to an existing one resulted in HTTP 500 errors. In nextcloud logs, there were &hellip; <a href=\"https:\/\/hauweele.net\/~gawen\/blog\/?p=2826\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[1206,572,1209,1205,1208,1207],"class_list":["post-2826","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-db","tag-migration","tag-mysql","tag-nextcloud","tag-postgresql","tag-sequence"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2826"}],"version-history":[{"count":0,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2826\/revisions"}],"wp:attachment":[{"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hauweele.net\/~gawen\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}