Files
012-kaopeilian/backend/migrations/manual_modify_knowledge_points_material_id.sql
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

27 lines
1.0 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 修改知识点表将material_id设为必填字段
-- 执行日期2025-09-27
-- 说明将knowledge_points表的material_id字段从可选改为必填
-- 1. 首先检查是否有material_id为NULL的记录
SELECT COUNT(*) as null_count FROM knowledge_points WHERE material_id IS NULL AND is_deleted = FALSE;
-- 2. 如果有NULL值需要先处理这些记录可以删除或设置默认值
-- 这里先删除material_id为NULL的记录如果有的话
DELETE FROM knowledge_points WHERE material_id IS NULL;
-- 3. 修改字段为NOT NULL并修改外键约束
ALTER TABLE knowledge_points
MODIFY COLUMN material_id INT NOT NULL COMMENT '关联资料ID';
-- 4. 删除旧的外键约束
ALTER TABLE knowledge_points
DROP FOREIGN KEY knowledge_points_ibfk_2;
-- 5. 添加新的外键约束CASCADE删除
ALTER TABLE knowledge_points
ADD CONSTRAINT knowledge_points_ibfk_2
FOREIGN KEY (material_id) REFERENCES course_materials(id) ON DELETE CASCADE;
-- 6. 验证修改结果
DESCRIBE knowledge_points;