From 85c7a85b0b757856e99d8680c9b99700c049fa7b Mon Sep 17 00:00:00 2001 From: Brian Foley Date: Wed, 3 Jun 2026 20:25:53 +0000 Subject: [PATCH] Make users.u_id UNIQUE for use as a FK in user_teams_membership MySQL 8.0 InnoDB allows foreign keys to ref an indexed but not unique column. This is deprecated by default in MySQL 8.4 (in Ubuntu 26.04) and produces the error `Failed to add the foreign key constraint. Missing unique key for constraint 'user_teams_membership_ibfk_1' in the referenced table 'users'` See https://dev.mysql.com/doc/refman/8.4/en/server-system-variables.html#sysvar_restrict_fk_on_non_standard_key --- SETUP/db_schema.sql | 2 +- .../25/20260603_make_users_u_id_unique.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 SETUP/upgrade/25/20260603_make_users_u_id_unique.php diff --git a/SETUP/db_schema.sql b/SETUP/db_schema.sql index e0dd47992..19b89bac6 100644 --- a/SETUP/db_schema.sql +++ b/SETUP/db_schema.sql @@ -655,7 +655,7 @@ CREATE TABLE `users` ( `navbar_activity_menu` tinyint NOT NULL DEFAULT '1', PRIMARY KEY (`username`), UNIQUE KEY `api_key` (`api_key`), - KEY `u_id` (`u_id`), + UNIQUE KEY `u_id` (`u_id`), KEY `last_login` (`last_login`), KEY `t_last_activity` (`t_last_activity`), KEY `api_key_username` (`api_key`,`username`), diff --git a/SETUP/upgrade/25/20260603_make_users_u_id_unique.php b/SETUP/upgrade/25/20260603_make_users_u_id_unique.php new file mode 100644 index 000000000..c429bfaeb --- /dev/null +++ b/SETUP/upgrade/25/20260603_make_users_u_id_unique.php @@ -0,0 +1,22 @@ +