After a NextCloud update you might encounter some of these errors:
Info: Pressing Ctrl-C will finish the currently running step and then stops the updater.
[✔] Check for expected files
[✔] Check for write permissions
[✔] Create backup
[✔] Downloading
[✔] Verify integrity
[✔] Extracting
[✔] Enable maintenance mode
[✔] Replace entry points
[✔] Delete old files
[✔] Move new files in place
[✔] Done
Update of code successful.
Should the "occ upgrade" command be executed? [Y/n] y
Setting log level to debug
Repair step: Repair MySQL collation
Repair info: All tables already have the correct collation -> nothing to do
Repair step: Copy data from accounts table when migrating from ownCloud
Repair step: Drop account terms table when migrating from ownCloud
Updating database schema
Exception: Database error when running migration 33000Date20251023120529 for app core
An index with name "unique_bucket_store" was already defined on table "oc_preview_locations".
Update failed
Maintenance mode is kept active
Resetting log level
"occ upgrade" failed - return code: 5
NextCloud will remain in maintenance mode
Retrieve the table definition:
MariaDB [nextcloud]> show create table oc_preview_locations;
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| oc_preview_locations | CREATE TABLE `oc_preview_locations` (
`id` bigint(20) unsigned NOT NULL,
`bucket_name` varchar(40) NOT NULL,
`object_store_name` varchar(40) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_bucket_store` (`bucket_name`,`object_store_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
Drop the index
MariaDB [nextcloud]> DROP INDEX IF EXISTS unique_bucket_store ON oc_preview_locations;
Query OK, 0 rows affected (0.010 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [nextcloud]> show create table oc_preview_locations;
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| oc_preview_locations | CREATE TABLE `oc_preview_locations` (
`id` bigint(20) unsigned NOT NULL,
`bucket_name` varchar(40) NOT NULL,
`object_store_name` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
Run occ upgrade
$ php occ upgrade
If upgrade completes successfully, disable mainteance mode
$ php occ maintenance:mode --off
Maintenance mode disabled