# HTTP 500 错误修复报告 ## 问题描述 修复 FilamentAdmin 访问时出现的 HTTP 500 内部服务器错误: - Question Bank API 返回:`HTTP request returned status code 500: Internal Server Error` - 日志错误:`sqlalchemy.exc.ProgrammingError: relation "prompt_templates" does not exist` ## 问题分析 Question Bank API 的 `/prompts` 端点尝试查询 `prompt_templates` 表,但该表在数据库中不存在,导致 SQL 执行失败,返回 HTTP 500 错误。 ## 修复内容 ### 1. 创建 prompt_templates 表 **操作**: 执行 `/Volumes/T9/code/math/apis/QuestionBankService/create_prompt_table.py` 脚本 **结果**: 成功创建 `prompt_templates` 表,包含以下字段: - `id` (UUID, 主键) - `template_name` (String(100), 唯一) - `template_type` (String(50)) - `template_content` (Text) - `variables` (Text) - `version` (Integer) - `is_active` (String(10)) - `description` (Text) - `tags` (String(200)) - `created_at` (DateTime) - `updated_at` (DateTime) ### 2. 插入默认提示词模板 成功插入 5 个默认模板: 1. **题目生成_基础版** - 模板类型:题目生成 - 用途:各类题型的批量生成 2. **掌握度评估_因式分解** - 模板类型:掌握度评估 - 用途:因式分解知识点掌握度评估 3. **技能熟练度分析** - 模板类型:技能熟练度 - 用途:针对单个技能的熟练度分析 4. **AI题目生成_增强版** - 模板类型:题目生成 - 用途:增强版AI题目生成,支持精确的难度和题型分布控制 5. **智能题目审核** - 模板类型:质量审核 - 用途:AI题目质量审核,自动识别问题并提供改进建议 ### 3. 验证 API 端点 所有 API 端点现在都正常工作: ``` ✅ GET /health - HTTP 200 ✅ GET /questions?page=1&per_page=5 - HTTP 200 ✅ GET /prompts?page=1&per_page=5 - HTTP 200 ✅ GET /questions/statistics - HTTP 200 ``` ## 执行步骤 1. **进入 QuestionBankService 目录** ```bash cd /Volumes/T9/code/math/apis/QuestionBankService ``` 2. **将创建脚本复制到容器** ```bash docker cp create_prompt_table.py api-question-bank:/app/ ``` 3. **在容器中执行脚本** ```bash docker exec -u 0 api-question-bank python /app/create_prompt_table.py ``` 4. **清理 Laravel 缓存** ```bash cd /Volumes/T9/code/math/apis/FilamentAdmin php artisan config:clear php artisan cache:clear php artisan view:clear ``` ## 数据库验证 确认表创建成功: ```sql SELECT * FROM prompt_templates; -- 返回 5 行记录,表明默认模板已插入 ``` ## 测试结果 ### API 响应示例 **GET /prompts?page=1&per_page=5** ```json [ { "id": "3597f1e3-a304-441e-a372-f20748d07915", "template_name": "智能题目审核", "template_type": "质量审核", "template_content": "对生成的数学题目进行智能审核...", "variables": "{\"question_code\": \"题目编号\", ...}", "version": 1, "is_active": null, "description": "AI题目质量审核模板...", "tags": "审核,质量,AI", "created_at": "2025-11-17T05:11:44.657556", "updated_at": "2025-11-17T05:11:44.657556" }, ... ] ``` ## 修复时间 2025-11-17 13:11 ## 修复人 Claude Code ## 总结 所有 HTTP 500 错误已完全解决: - ✅ `prompt_templates` 表已创建 - ✅ 默认提示词模板已插入 - ✅ 所有 API 端点正常响应 - ✅ Laravel 缓存已清理 现在可以正常访问 FilamentAdmin 管理后台,所有功能应该都能正常工作。