dingdanquanliucheng/fix_missing_columns.sql
2026-06-01 11:24:20 +08:00

29 lines
2.1 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.

-- 修复 ORM 模型与实际数据库表结构不一致的问题
-- 问题ORM 模型定义了多个列,但数据库表中不存在,导致 SQLAlchemy 查询报 Unknown column 错误
-- 执行日期2026-05-31
-- ============================================
-- 1. product 表:添加 ORM 模型中存在但数据库缺失的 6 个列
-- ============================================
ALTER TABLE `product`
ADD COLUMN `pricing_type` varchar(32) NULL DEFAULT NULL COMMENT '计价方式area/weight' AFTER `sale_price`,
ADD COLUMN `pricing_unit` varchar(16) NULL DEFAULT '' COMMENT '计价单位' AFTER `pricing_type`,
ADD COLUMN `thickness` varchar(32) NULL DEFAULT NULL COMMENT '厚度' AFTER `pricing_unit`,
ADD COLUMN `weight_gsm` int NULL DEFAULT NULL COMMENT '克重(gsm)' AFTER `thickness`,
ADD COLUMN `default_width_m` decimal(10,4) NULL DEFAULT NULL COMMENT '默认宽度(米)' AFTER `weight_gsm`,
ADD COLUMN `is_default` int NOT NULL DEFAULT 0 COMMENT '是否默认规格0否 1是' AFTER `status`;
-- ============================================
-- 2. sales_order_item 表:添加 ORM 模型中存在但数据库缺失的 8 个列
-- ============================================
ALTER TABLE `sales_order_item`
ADD COLUMN `pricing_type` varchar(32) NULL DEFAULT NULL COMMENT '计价方式area/weight' AFTER `other_fee_amount`,
ADD COLUMN `length_m` decimal(10,4) NULL DEFAULT NULL COMMENT '长度(米)' AFTER `pricing_type`,
ADD COLUMN `width_m` decimal(10,4) NULL DEFAULT NULL COMMENT '宽度(米)' AFTER `length_m`,
ADD COLUMN `area_sqm` decimal(18,4) NULL DEFAULT NULL COMMENT '面积(平方米)' AFTER `width_m`,
ADD COLUMN `surcharge_detail` text NULL DEFAULT NULL COMMENT '附加费用明细' AFTER `area_sqm`,
ADD COLUMN `processing_detail` text NULL DEFAULT NULL COMMENT '加工费用明细' AFTER `surcharge_detail`,
ADD COLUMN `supplier_id` int NULL DEFAULT NULL COMMENT '供应商ID' AFTER `processing_detail`,
ADD COLUMN `supplier_model` varchar(64) NULL DEFAULT NULL COMMENT '供应商型号' AFTER `supplier_id`,
ADD COLUMN `price_tier` varchar(32) NULL DEFAULT NULL COMMENT '价格层级' AFTER `supplier_model`;