""" 检查数据库表结构,确认template_code字段是否存在 """ import pymysql import os DB_CONFIG = { 'host': os.getenv('DB_HOST', '152.136.177.240'), 'port': int(os.getenv('DB_PORT', 5012)), 'user': os.getenv('DB_USER', 'finyx'), 'password': os.getenv('DB_PASSWORD', '6QsGK6MpePZDE57Z'), 'database': os.getenv('DB_NAME', 'finyx'), 'charset': 'utf8mb4' } TENANT_ID = 615873064429507639 def check_table_structure(): """检查表结构""" print("="*60) print("检查数据库表结构") print("="*60) try: conn = pymysql.connect(**DB_CONFIG) cursor = conn.cursor() # 检查f_polic_file_config表结构 print("\n1. 检查 f_polic_file_config 表结构:") cursor.execute("DESCRIBE f_polic_file_config") columns = cursor.fetchall() has_template_code = False has_input_data = False for col in columns: col_name = col[0] col_type = col[1] print(f" - {col_name}: {col_type}") if col_name == 'template_code': has_template_code = True if col_name == 'input_data': has_input_data = True print(f"\n template_code 字段: {'✓ 存在' if has_template_code else '✗ 不存在'}") print(f" input_data 字段: {'✓ 存在' if has_input_data else '✗ 不存在'}") if not has_template_code: print("\n ⚠ 警告:template_code字段不存在,可能需要添加该字段") print(" 请联系数据库管理员添加该字段") # 检查是否有数据 print("\n2. 检查文件配置数据:") cursor.execute(""" SELECT COUNT(*) FROM f_polic_file_config WHERE tenant_id = %s """, (TENANT_ID,)) count = cursor.fetchone()[0] print(f" 找到 {count} 个文件配置记录") if count > 0: # 检查template_code字段是否有值 if has_template_code: cursor.execute(""" SELECT COUNT(*) FROM f_polic_file_config WHERE tenant_id = %s AND template_code IS NOT NULL AND template_code != '' """, (TENANT_ID,)) code_count = cursor.fetchone()[0] print(f" 其中 {code_count} 个记录有template_code值") if code_count < count: print(f" ⚠ 建议运行: python update_template_code_field.py") # 检查字段数据 print("\n3. 检查字段数据:") cursor.execute(""" SELECT COUNT(*) FROM f_polic_field WHERE tenant_id = %s """, (TENANT_ID,)) field_count = cursor.fetchone()[0] print(f" 找到 {field_count} 个字段记录") if field_count == 0: print(" ⚠ 建议运行: python init_all_fields_from_excel.py") cursor.close() conn.close() print("\n" + "="*60) print("检查完成") print("="*60) return True except Exception as e: print(f"\n✗ 检查失败: {e}") import traceback traceback.print_exc() return False if __name__ == '__main__': check_table_structure()