fix: 创建V12安全处理订单明细外键约束
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
-- 安全处理订单明细外键约束(使用IF EXISTS避免重复执行报错)
|
||||||
|
-- 先检查约束是否存在,存在则删除
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT 1 FROM information_schema.table_constraints
|
||||||
|
WHERE constraint_name = 'order_items_product_id_fkey'
|
||||||
|
AND table_name = 'order_items'
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE order_items DROP CONSTRAINT IF EXISTS order_items_product_id_fkey;
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
-- 重新添加外键约束(不级联删除)
|
||||||
|
ALTER TABLE order_items ADD CONSTRAINT order_items_product_id_fkey
|
||||||
|
FOREIGN KEY (product_id) REFERENCES products(product_id);
|
||||||
Reference in New Issue
Block a user