Files
weibo_signin/migrate_fix_signin_logs_fk.sql

11 lines
414 B
MySQL
Raw Normal View History

2026-04-01 15:13:37 +08:00
-- 修复 signin_logs 外键
2026-04-01 15:09:21 +08:00
-- 用法: mysql -u weibo -p123456 weibo_hotsign < migrate_fix_signin_logs_fk.sql
2026-04-01 15:13:37 +08:00
-- 1. 清理孤儿记录
DELETE FROM signin_logs WHERE account_id NOT IN (SELECT id FROM accounts);
2026-04-01 15:09:21 +08:00
2026-04-01 15:13:37 +08:00
-- 2. 重建外键(带 CASCADE忽略已存在的情况
2026-04-01 15:09:21 +08:00
ALTER TABLE signin_logs
ADD CONSTRAINT fk_signin_logs_account
FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE;