From 204cb223a3d54485da3a42b428a02598d2a0d650 Mon Sep 17 00:00:00 2001 From: "DESKTOP-72TV0V4\\caoxiaozhu" Date: Sat, 21 Mar 2026 12:02:35 +0800 Subject: [PATCH] Fix Log model registration - import models before init_db The Log model was not being registered with SQLAlchemy's metadata, causing the logs table to not be created on startup. --- backend/app/main.py | 1 + backend/app/models/__init__.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/backend/app/main.py b/backend/app/main.py index 089c660..19f6399 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -2,6 +2,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.database import init_db +import app.models # noqa: F401 - 注册所有模型 from app.routers import ( auth_router, conversation_router, diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.py index 3446d05..3a44a2e 100644 --- a/backend/app/models/__init__.py +++ b/backend/app/models/__init__.py @@ -8,6 +8,7 @@ from app.models.conversation import Conversation, Message from app.models.knowledge_graph import KGNode, KGEdge from app.models.memory import MemorySummary, UserMemory from app.models.todo import DailyTodo, TodoSource +from app.models.log import Log, LogType, LogLevel __all__ = [ "Base", @@ -28,4 +29,7 @@ __all__ = [ "UserMemory", "DailyTodo", "TodoSource", + "Log", + "LogType", + "LogLevel", ]