Getting error An index with name 'primary' was already defined on table 'oc_bookmarks_tags'

Hi

while I am trying to update nextcloud apps, I started seeing this error:

# sudo -u www-data /var/www/html/nextcloud/occ -v app:update bookmarks

bookmarks new version available: 4.4.0

Error: An index with name 'primary' was already defined on table 'oc_bookmarks_tags'.

so I jumped into mysql db
MariaDB [nextcloud]> desc oc_bookmarks_tags;

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| bookmark_id | bigint(20)   | YES  | MUL | NULL    |                |
| tag         | varchar(255) | NO   |     |         |                |
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
+-------------+--------------+------+-----+---------+----------------+

then I decided to look at old nextcloud db from the backed up

MariaDB [nextcloud]> desc oc_bookmarks_tags;

+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| bookmark_id | bigint(20)   | YES  | MUL | NULL    |                |
| tag         | varchar(255) | NO   |     |         |                |
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
+-------------+--------------+------+-----+---------+----------------+

I see there is no change so why is it erroring now ?

The tags table shouldn’t have an id column, least of all as a primary key. I’m not sure how this happened, but the latest version tries to set a new primary key for that table and fails because there is one already.

I removed the Primary Key and its seem to be working now.

MariaDB [nextcloud]> desc oc_bookmarks_tags;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| bookmark_id | bigint(20)   | YES  | MUL | NULL    |                |
| tag         | varchar(255) | NO   |     |         |                |
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
+-------------+--------------+------+-----+---------+----------------+
3 rows in set (0.010 sec)
MariaDB [nextcloud]> ALTER TABLE oc_bookmarks_tags MODIFY id INT NOT NULL;
Query OK, 0 rows affected (0.236 sec)
Records: 0  Duplicates: 0  Warnings: 0
MariaDB [nextcloud]> ALTER TABLE oc_bookmarks_tags DROP PRIMARY KEY;
Query OK, 23 rows affected (0.483 sec)             
Records: 23  Duplicates: 0  Warnings: 0
MariaDB [nextcloud]> desc oc_bookmarks_tags;
+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| bookmark_id | bigint(20)   | YES  | MUL | NULL    |       |
| tag         | varchar(255) | NO   |     |         |       |
| id          | int(11)      | NO   |     | NULL    |       |
+-------------+--------------+------+-----+---------+-------+
3 rows in set (0.057 sec)

MariaDB [nextcloud]> desc oc_bookmarks_tags;

+-------------+--------------+------+-----+---------+-------+
| Field       | Type         | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| bookmark_id | bigint(20)   | NO   | PRI | NULL    |       |
| tag         | varchar(255) | NO   | PRI |         |       |
| id          | int(11)      | NO   |     | NULL    |       |
+-------------+--------------+------+-----+---------+-------+

it sets the primary key on tag and bookmark_id instead. If it was required to be set on tag instead of id then it occ app:update bookmarks should just remove the primary key where it is and apply on the column where it is needed.

Due to this issue anyone landing on my nextcloud page was able to see start update button without login.

I agree, but this is the first time I hear of an id column on that table. It’s very peculiar and it’s rather unlikely that the app created that column. Otherwise the 7000 people that have installed the app so far would have had the same problem as you.