ETest-Vue-FastAPI/QUICKFIX_批次ID类型错误.md

70 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 快速修复批次ID类型错误
## 错误信息
```
(asyncmy.errors.DataError) (1264, "Out of range value for column 'batch_id' at row 1")
```
## 原因
`batch_id` 字段类型为 INTEGER但时间戳值 `1767883391558` 超出了 INTEGER 的最大值 `2147483647`
## 解决步骤
### 1. 执行数据库修复(必须)
```bash
mysql -u root -p your_database < fix_batch_id_bigint.sql
```
或者手动执行:
```sql
ALTER TABLE test_work_order
MODIFY COLUMN batch_id BIGINT NULL COMMENT '工单批次ID用于分组标识';
```
### 2. 重启后端服务(必须)
```bash
# 停止后端服务
# 启动后端服务
```
### 3. 验证修复
```sql
-- 查看字段类型
DESCRIBE test_work_order;
-- 应该看到:
-- batch_id | bigint | YES | | NULL |
```
### 4. 测试
1. 进入样品管理页面
2. 选择样品,点击"生成工单"
3. 填写工单名称,提交
4. **应该成功**,不再报错
## 技术说明
### INTEGER vs BIGINT
- **INTEGER**: -2147483648 到 2147483647
- **BIGINT**: -9223372036854775808 到 9223372036854775807
### 时间戳计算
```python
# 毫秒级时间戳
batch_id = int(datetime.now().timestamp() * 1000)
# 例如1767883391558超出 INTEGER 范围)
```
### SQLAlchemy 类型映射
- `Integer` → MySQL `INT`
- `BigInteger` → MySQL `BIGINT`
## 已修改的文件
-`fix_batch_id_bigint.sql` - 数据库修复脚本
-`add_workorder_batch_field.sql` - 更新为 BIGINT
-`test_work_order_do.py` - 使用 BigInteger
-`工单批次分组功能实现说明.md` - 更新文档
## 完成时间
2026-01-08 22:45