nextcloud / polls

🗳️ Polls app for Nextcloud
https://apps.nextcloud.com/apps/polls
GNU Affero General Public License v3.0
257 stars 73 forks source link

Error when updating to 30.0.2: Foreign key constraint is incorrectly formed #3778

Open m8ichael opened 6 days ago

m8ichael commented 6 days ago

⚠️ This issue respects the following points: ⚠️

What went wrong, what did you observe?

When I updated to NC 30.0.2, I got a problem updating polls.

I first tried to disable polls, delete the tables ocpolls*, restore them from backup an re-enabled polls, but the problem persists.

What did you expect, how polls should behave instead?

No error message when the upgrade-command is executed

What steps does it need to replay this bug?

  1. The problem appears when I do the command: occ maintenance:repair --include-expensive

Installation method

Installed/updated from the appstore (Apps section of your site)

Installation type

Updated from previous major version (i.e. 3.x.x to 4.x.x)

Affected polls version

7.2.4

Which browser did you use, when experiencing the bug?

Other browser

No response

Add your browser log here

Additional client environment information

No response

NC version

Nextcloud 30

Other Nextcloud version

No response

PHP engine version

PHP 8.3

Other PHP version

No response

Database engine

MariaDB

Database Engine version or other Database

10.5.8

Which user-backends are you using?

Add your nextcloud server log here

no logs for polls found

Additional environment informations

No response

Configuration report

{
    "system": {
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "cloud.alpenverein-hannover.de"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "30.0.2.2",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "default_language": "de",
        "default_locale": "de_DE",
        "installed": true,
        "remember_login_cookie_lifetime": 1296000,
        "session_lifetime": 86400,
        "session_keepalive": true,
        "skeletondirectory": "",
        "knowledgebaseenabled": false,
        "lost_password_link": "disabled",
        "ldapIgnoreNamingRules": false,
        "ldapProviderFactory": "\\OCA\\User_LDAP\\LDAPProviderFactory",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpmode": "smtp",
        "mail_smtpauthtype": "LOGIN",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "auth.bruteforce.protection.enabled": true,
        "maintenance": false,
        "updater.release.channel": "stable",
        "maintenance_window_start": 1,
        "theme": "",
        "loglevel": 2,
        "forcessl": true,
        "forceSSLforSubdomains": true,
        "trashbin_retention_obligation": "7, 20",
        "has_internet_connection": true,
        "check_for_working_webdav": true,
        "check_for_working_wellknown_setup": true,
        "check_for_working_htaccess": true,
        "cron_log": true,
        "logtimezone": "Europe\/Berlin",
        "logdateformat": "F d, Y H:i:s",
        "ldapUserCleanupInterval": 51,
        "filelocking.enabled": "true",
        "mail_smtpsecure": "ssl",
        "mail_smtpauth": 1,
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": "465",
        "mail_smtpname": "***REMOVED SENSITIVE VALUE***",
        "mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
        "overwrite.cli.url": "https:\/\/cloud.alpenverein-hannover.de",
        "share_folder": "\/Mit mir geteilt",
        "app_install_overwrite": [
            "calendar",
            "circles",
            "groupfolders",
            "ocr",
            "impersonate",
            "bruteforcesettings",
            "twofactor_gateway",
            "issuetemplate",
            "checksum_api"
        ],
        "twofactor_enforced": "true",
        "twofactor_enforced_groups": [
            "AdminUser2F"
        ],
        "twofactor_enforced_excluded_groups": [],
        "mysql.utf8mb4": true,
        "default_phone_region": "DE",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 0,
            "timeout": 0
        },
        "preview_max_x": 1024,
        "preview_max_y": 768,
        "preview_max_scale_factor": 1,
        "activity_expire_days": 30,
        "allow_local_remote_servers": true
    }
}

List of activated Apps

Enabled:
  - activity: 3.0.0
  - admin_audit: 1.20.0
  - announcementcenter: 7.0.1
  - app_api: 4.0.0
  - bruteforcesettings: 3.0.0
  - calendar: 5.0.1
  - calendar_resource_management: 0.8.0
  - checksum: 1.2.5
  - circles: 30.0.0
  - cloud_federation_api: 1.13.0
  - comments: 1.20.1
  - contacts: 6.1.1
  - dav: 1.31.1
  - deck: 1.14.2
  - drawio: 3.0.3
  - external: 5.5.2
  - federatedfilesharing: 1.20.0
  - federation: 1.20.0
  - files: 2.2.0
  - files_downloadactivity: 1.17.0
  - files_downloadlimit: 3.0.0
  - files_external: 1.22.0
  - files_reminders: 1.3.0
  - files_sharing: 1.22.0
  - files_trashbin: 1.20.1
  - files_versions: 1.23.0
  - groupfolders: 18.0.5
  - impersonate: 1.17.0
  - logreader: 3.0.0
  - lookup_server_connector: 1.18.0
  - notifications: 3.0.0
  - oauth2: 1.18.1
  - onlyoffice: 9.5.0
  - ownershiptransfer: 1.0.1
  - password_policy: 2.0.0
  - passwords: 2024.11.20
  - polls: 7.2.4
  - privacy: 2.0.0
  - provisioning_api: 1.20.0
  - quota_warning: 1.20.0
  - recommendations: 3.0.0
  - related_resources: 1.5.0
  - serverinfo: 2.0.0
  - settings: 1.13.0
  - sharebymail: 1.20.0
  - text: 4.1.0
  - theming: 2.5.0
  - theming_customcss: 1.17.0
  - twofactor_backupcodes: 1.19.0
  - twofactor_totp: 12.0.0-dev
  - updatenotification: 1.20.0
  - user_ldap: 1.21.0
  - viewer: 3.0.0
  - webhook_listeners: 1.1.0-dev
  - workflowengine: 2.12.0
Disabled:
  - apporder: 0.15.0 (installed 0.15.0)
  - contactsinteraction: 1.11.0 (installed 1.2.0)
  - dashboard: 7.10.0 (installed 7.0.0)
  - encryption: 2.18.0
  - files_accesscontrol: 1.19.1 (installed 1.19.1)
  - files_automatedtagging: 1.19.0 (installed 1.19.0)
  - files_mindmap: 0.0.30 (installed 0.0.30)
  - files_pdfviewer: 3.0.0 (installed 1.2.1)
  - files_rightclick: 0.15.1 (installed 1.6.0)
  - firstrunwizard: 3.0.0 (installed 2.1)
  - geoblocker: 0.5.15 (installed 0.5.15)
  - integration_zammad: 3.0.1 (installed 3.0.1)
  - issuetemplate: 0.7.0 (installed 0.7.0)
  - mail: 3.7.9 (installed 3.7.9)
  - nextcloud_announcements: 2.0.0 (installed 1.10.0)
  - occweb: 0.2.0 (installed 0.2.0)
  - photos: 3.0.2 (installed 1.0.0)
  - spreed: 19.0.11 (installed 19.0.11)
  - support: 2.0.0 (installed 1.0.0)
  - survey_client: 2.0.0 (installed 1.3.0)
  - suspicious_login: 8.0.0
  - systemtags: 1.20.0 (installed 1.11.0)
  - tasks: 0.16.1 (installed 0.16.1)
  - terms_of_service: 4.0.0 (installed 4.0.0)
  - twofactor_nextcloud_notification: 4.0.0
  - user_status: 1.10.0 (installed 1.1.1)
  - weather_status: 1.10.0 (installed 1.1.0)

Nextcloud Signing status

No errors have been found.

Additional Information

No response

dartcafe commented 3 days ago

have you tried occ polls:db:rebuild?

m8ichael commented 2 days ago

@dartcafe Yes, I tried that, but with no results. The error still exists.

dartcafe commented 2 days ago

That makes no sense. occ polls:db:rebuild removes all indices and foreign key constraints. After that the tables are checked and updated (or created, if not existent). So there can't exist any foreign key constraint affecting the polls tables.

Either the error message is misleading or something else exists inside the database, preventing the action. Is there any stack trace of the error?

What confuses me, is that the creation of the comments table is reported to be failing. This leads to the conclusion, that it does not exist.

An export of the table definitions could help.

m8ichael commented 2 days ago

OK, here we go... ;-) Here's a dump of the exported structure:

-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Erstellungszeit: 20. Nov 2024 um 02:40
-- Server-Version: 10.5.8-MariaDB
-- PHP-Version: 8.2.21

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";

--
-- Datenbank: `nextcloud`
--

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_comments`
--

CREATE TABLE `oc_polls_comments` (
  `id` bigint(20) NOT NULL,
  `poll_id` bigint(20) NOT NULL DEFAULT 0,
  `user_id` varchar(256) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `comment` varchar(1024) COLLATE utf8mb4_bin DEFAULT NULL,
  `timestamp` bigint(20) NOT NULL DEFAULT 0,
  `deleted` bigint(20) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_log`
--

CREATE TABLE `oc_polls_log` (
  `id` bigint(20) NOT NULL,
  `created` bigint(20) NOT NULL DEFAULT 0,
  `processed` bigint(20) NOT NULL DEFAULT 0,
  `poll_id` bigint(20) NOT NULL DEFAULT 0,
  `user_id` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  `display_name` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  `message_id` varchar(64) COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_notif`
--

CREATE TABLE `oc_polls_notif` (
  `id` bigint(20) NOT NULL,
  `poll_id` bigint(20) NOT NULL DEFAULT 0,
  `user_id` varchar(256) COLLATE utf8mb4_bin NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_options`
--

CREATE TABLE `oc_polls_options` (
  `id` bigint(20) NOT NULL,
  `poll_id` bigint(20) NOT NULL DEFAULT 0,
  `poll_option_text` varchar(1024) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `timestamp` bigint(20) NOT NULL DEFAULT 0,
  `order` bigint(20) NOT NULL DEFAULT 0,
  `confirmed` bigint(20) NOT NULL DEFAULT 0,
  `duration` bigint(20) NOT NULL DEFAULT 0,
  `owner` varchar(256) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `released` bigint(20) NOT NULL DEFAULT 0,
  `poll_option_hash` varchar(256) COLLATE utf8mb4_bin DEFAULT '',
  `deleted` bigint(20) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_polls`
--

CREATE TABLE `oc_polls_polls` (
  `id` bigint(20) NOT NULL,
  `type` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT 'datePoll',
  `title` varchar(128) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `description` text COLLATE utf8mb4_bin DEFAULT NULL,
  `owner` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  `created` bigint(20) NOT NULL DEFAULT 0,
  `expire` bigint(20) NOT NULL DEFAULT 0,
  `deleted` bigint(20) NOT NULL DEFAULT 0,
  `access` varchar(1024) COLLATE utf8mb4_bin NOT NULL DEFAULT 'private',
  `anonymous` bigint(20) NOT NULL DEFAULT 0,
  `allow_maybe` bigint(20) NOT NULL DEFAULT 1,
  `vote_limit` bigint(20) NOT NULL DEFAULT 0,
  `show_results` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT 'always',
  `admin_access` bigint(20) NOT NULL DEFAULT 0,
  `option_limit` bigint(20) NOT NULL DEFAULT 0,
  `allow_comment` bigint(20) NOT NULL DEFAULT 1,
  `hide_booked_up` bigint(20) NOT NULL DEFAULT 1,
  `allow_proposals` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT 'disallow',
  `use_no` bigint(20) NOT NULL DEFAULT 1,
  `proposals_expire` bigint(20) NOT NULL DEFAULT 0,
  `misc_settings` text COLLATE utf8mb4_bin DEFAULT NULL,
  `last_interaction` bigint(20) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_preferences`
--

CREATE TABLE `oc_polls_preferences` (
  `id` bigint(20) NOT NULL,
  `user_id` varchar(256) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `timestamp` bigint(20) NOT NULL DEFAULT 0,
  `preferences` text COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_share`
--

CREATE TABLE `oc_polls_share` (
  `id` bigint(20) NOT NULL,
  `token` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `type` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `poll_id` bigint(20) NOT NULL DEFAULT 0,
  `user_id` varchar(256) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `invitation_sent` bigint(20) NOT NULL DEFAULT 0,
  `display_name` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  `email_address` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
  `reminder_sent` bigint(20) NOT NULL DEFAULT 0,
  `misc_settings` text COLLATE utf8mb4_bin DEFAULT NULL,
  `locked` bigint(20) NOT NULL DEFAULT 0,
  `label` varchar(256) COLLATE utf8mb4_bin DEFAULT '',
  `deleted` bigint(20) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_votes`
--

CREATE TABLE `oc_polls_votes` (
  `id` bigint(20) NOT NULL,
  `poll_id` bigint(20) NOT NULL DEFAULT 0,
  `user_id` varchar(256) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `vote_option_id` bigint(20) NOT NULL DEFAULT 0,
  `vote_option_text` varchar(1024) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `vote_answer` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `vote_option_hash` varchar(256) COLLATE utf8mb4_bin DEFAULT '',
  `deleted` bigint(20) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=COMPRESSED;

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `oc_polls_watch`
--

CREATE TABLE `oc_polls_watch` (
  `id` bigint(20) NOT NULL,
  `poll_id` bigint(20) NOT NULL DEFAULT 0,
  `table` varchar(64) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `updated` bigint(20) NOT NULL DEFAULT 0,
  `session_id` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

--
-- Indizes der exportierten Tabellen
--

--
-- Indizes für die Tabelle `oc_polls_preferences`
--
ALTER TABLE `oc_polls_preferences`
  ADD UNIQUE KEY `UNIQ_preferences` (`user_id`);
COMMIT;

All tables exist on the database.

dartcafe commented 2 days ago

There is no hint inside the table structure, which may help to analyze the error.

I need more details about the error line, to get an idea, what is wrong. It seems the error does not describe a failure on creating the table but attaching the fk. There should be more information within the printed error which names the failing fk structure.

m8ichael commented 1 day ago

OK, now I got an error, when I try to use occ polls:db:rebuild:

Step 3. Create or update tables to current shema
 - Set db structure
   Validating table oc_polls_polls
   Validating table oc_polls_options
   Validating table oc_polls_votes
   Validating table oc_polls_comments
   Validating table oc_polls_share
   Validating table oc_polls_notif
   Validating table oc_polls_log
   Validating table oc_polls_watch
   Validating table oc_polls_preferences

In DbalException.php line 54:

  An exception occurred while executing a query: SQLSTATE[42000]: Syntax erro
  r or access violation: 1075 Incorrect table definition; there can be only o
  ne auto column and it must be defined as a key

In ExceptionConverter.php line 118:

  An exception occurred while executing a query: SQLSTATE[42000]: Syntax erro
  r or access violation: 1075 Incorrect table definition; there can be only o
  ne auto column and it must be defined as a key

In Exception.php line 28:

  SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table def
  inition; there can be only one auto column and it must be defined as a key

In Connection.php line 33:

  SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table def
  inition; there can be only one auto column and it must be defined as a key