debug: 创建数据库表结构检查脚本
问题定位:生成日报失败,错误显示 "Unknown column 'total_money'" 原因:用户选择的字段名在数据库中不存在。 解决方案: 1. 运行 python check_table_structure.py 查看实际字段 2. 使用实际存在的字段名创建配置 3. 重新生成日报 运行方式: ```bash python check_table_structure.py ``` 脚本会列出所有字段,请使用这些字段名创建配置。 Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
62
check_table_structure.py
Normal file
62
check_table_structure.py
Normal file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
检查数据库表结构
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
from lib.db import execute_query
|
||||
|
||||
def check_table_structure():
|
||||
"""检查表结构"""
|
||||
print("="*60)
|
||||
print("检查 t_equipment_charge_order 表结构")
|
||||
print("="*60)
|
||||
|
||||
try:
|
||||
# 查询表结构
|
||||
sql = "DESCRIBE t_equipment_charge_order"
|
||||
columns = execute_query(sql)
|
||||
|
||||
print(f"\n表中共有 {len(columns)} 个字段:\n")
|
||||
|
||||
field_names = []
|
||||
for col in columns:
|
||||
field_name = col.get('Field')
|
||||
field_type = col.get('Type')
|
||||
field_names.append(field_name)
|
||||
print(f" - {field_name}: {field_type}")
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("常用字段检查:")
|
||||
print("="*60)
|
||||
|
||||
# 检查常用字段是否存在
|
||||
common_fields = [
|
||||
'order_no', 'report_time', 'total_money', 'charge_money',
|
||||
'service_money', 'electricity_money', 'charge_energy',
|
||||
'company_id', 'user_id', 'state', 'start_time', 'end_time'
|
||||
]
|
||||
|
||||
print("\n常用字段存在情况:")
|
||||
for field in common_fields:
|
||||
exists = "✓" if field in field_names else "✗"
|
||||
print(f" {exists} {field}")
|
||||
|
||||
print("\n" + "="*60)
|
||||
print("建议:")
|
||||
print("="*60)
|
||||
print("\n请使用上面列出的实际字段名创建配置!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ 查询失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
input("\n按回车键退出...")
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_table_structure()
|
||||
Reference in New Issue
Block a user