-- 修复外键约束，添加级联删除

-- 1. 修复 payments 表的外键约束
ALTER TABLE payments DROP FOREIGN KEY payments_ibfk_1;
ALTER TABLE payments ADD CONSTRAINT payments_user_fk 
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;

-- 2. 修复 orders 表的外键约束
ALTER TABLE orders DROP FOREIGN KEY orders_ibfk_1;
ALTER TABLE orders ADD CONSTRAINT orders_user_fk 
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
