97 lines
3.3 KiB
SQL
97 lines
3.3 KiB
SQL
-- ==========================================
|
|
-- 添加缺失的religion字段
|
|
-- 版本:V2.2.1
|
|
-- 功能:添加遗漏的宗教信仰字段(兼容MySQL语法)
|
|
-- 作者:Cursor AI 辅助
|
|
-- 时间:2025-01-12
|
|
-- 问题:实体类中有religion字段,但数据库表中缺失
|
|
-- ==========================================
|
|
|
|
-- 设置字符集
|
|
SET NAMES utf8mb4;
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
-- ----------------------------
|
|
-- 添加缺失的 religion 字段
|
|
-- ----------------------------
|
|
|
|
-- 检查字段是否已存在
|
|
SELECT '=== 检查religion字段是否存在 ===' as 'Result';
|
|
|
|
SELECT
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ religion 字段已存在' ELSE '❌ religion 字段不存在,需要添加' END as 'religion_check'
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'religion';
|
|
|
|
-- 直接添加 religion 字段
|
|
ALTER TABLE `xg_student_info`
|
|
ADD COLUMN `religion` varchar(20) DEFAULT NULL COMMENT '宗教信仰' AFTER `special_condition`;
|
|
|
|
-- 验证字段添加结果
|
|
SELECT '=== 验证religion字段添加结果 ===' as 'Result';
|
|
|
|
SELECT
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ religion 字段添加成功' ELSE '❌ religion 字段添加失败' END as 'religion_add_result'
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'religion';
|
|
|
|
-- 测试包含religion字段的查询
|
|
SELECT '=== 测试包含religion字段的查询 ===' as 'Result';
|
|
|
|
SELECT COUNT(*) as '包含religion字段的查询测试'
|
|
FROM xg_student_info
|
|
WHERE tenant_id = '000000'
|
|
AND deleted = 0
|
|
LIMIT 1;
|
|
|
|
-- 显示最终字段统计
|
|
SELECT '=== 最终字段统计 ===' as 'Result';
|
|
|
|
SELECT COUNT(*) as '总字段数'
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info';
|
|
|
|
-- 验证所有关键字段都存在
|
|
SELECT '=== 验证所有关键字段 ===' as 'Result';
|
|
|
|
SELECT
|
|
'religion' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'religion'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'current_address' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'current_address'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'special_condition' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'special_condition'
|
|
|
|
UNION ALL
|
|
|
|
SELECT
|
|
'is_poor_student' as field_name,
|
|
CASE WHEN COUNT(*) > 0 THEN '✅ 存在' ELSE '❌ 缺失' END as status
|
|
FROM information_schema.COLUMNS
|
|
WHERE table_schema = DATABASE() AND table_name = 'xg_student_info' AND column_name = 'is_poor_student';
|
|
|
|
-- 恢复外键检查
|
|
SET FOREIGN_KEY_CHECKS = 1;
|
|
|
|
-- ----------------------------
|
|
-- 脚本执行完成提示
|
|
-- ----------------------------
|
|
SELECT '==============================' as 'Result';
|
|
SELECT '✅ religion字段添加完成!' as 'Result';
|
|
SELECT '✅ 解决Unknown column religion错误' as 'Result';
|
|
SELECT '请重启后端服务并重新测试' as 'Result';
|
|
SELECT '==============================' as 'Result'; |