From 8a630508f40e9e1ade55a261990708c3dcab6889 Mon Sep 17 00:00:00 2001 From: Jukka Lampikoski Date: Tue, 10 Mar 2026 16:24:25 +0200 Subject: [PATCH] fix: add DEFAULT CHARSET=utf8mb4 to all tables Foreign key constraints fail if charset doesn't match between referencing and referenced tables. Added utf8mb4 to user_companies, reset_tokens, and login_attempts tables. Co-Authored-By: Claude Opus 4.6 --- db.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/db.php b/db.php index d4c8138..1f7e265 100644 --- a/db.php +++ b/db.php @@ -148,7 +148,7 @@ function initDatabase(): void { PRIMARY KEY (user_id, company_id), FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE CASCADE - ) ENGINE=InnoDB", + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "CREATE TABLE IF NOT EXISTS user_signatures ( id INT AUTO_INCREMENT PRIMARY KEY, @@ -170,14 +170,14 @@ function initDatabase(): void { token VARCHAR(64) NOT NULL UNIQUE, created_at DATETIME NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE - ) ENGINE=InnoDB", + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "CREATE TABLE IF NOT EXISTS login_attempts ( id INT AUTO_INCREMENT PRIMARY KEY, ip VARCHAR(45) NOT NULL, attempted_at DATETIME NOT NULL, INDEX idx_ip_time (ip, attempted_at) - ) ENGINE=InnoDB", + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "CREATE TABLE IF NOT EXISTS customers ( id VARCHAR(20) PRIMARY KEY,