all in
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
-- ========================================
|
||||
-- 修复重复的外键约束问题
|
||||
-- ========================================
|
||||
-- 问题:evaluation_point_groups_id 列有两个外键约束,导致 PostgREST 嵌套查询失败
|
||||
|
||||
-- 步骤 1: 删除旧的外键约束
|
||||
ALTER TABLE evaluation_points
|
||||
DROP CONSTRAINT IF EXISTS fk_evaluation_points_group;
|
||||
|
||||
-- 步骤 2: 验证删除结果(应该只剩下 2 个外键)
|
||||
SELECT
|
||||
tc.constraint_name AS "约束名",
|
||||
kcu.column_name AS "列名",
|
||||
ccu.table_name AS "引用表",
|
||||
ccu.column_name AS "引用列"
|
||||
FROM information_schema.table_constraints AS tc
|
||||
JOIN information_schema.key_column_usage AS kcu
|
||||
ON tc.constraint_name = kcu.constraint_name
|
||||
JOIN information_schema.constraint_column_usage AS ccu
|
||||
ON ccu.constraint_name = tc.constraint_name
|
||||
WHERE tc.constraint_type = 'FOREIGN KEY'
|
||||
AND tc.table_name = 'evaluation_points'
|
||||
AND kcu.column_name IN ('evaluation_point_groups_id', 'evaluation_point_groups_pid')
|
||||
ORDER BY kcu.column_name;
|
||||
|
||||
-- 预期结果(应该只有 2 个外键):
|
||||
-- 约束名 | 列名 | 引用表 | 引用列
|
||||
-- ------------------------------------------|-------------------------------|---------------------------|-------
|
||||
-- fk_evaluation_points_child_group | evaluation_point_groups_id | evaluation_point_groups | id
|
||||
-- fk_evaluation_points_parent_group | evaluation_point_groups_pid | evaluation_point_groups | id
|
||||
Reference in New Issue
Block a user