From e6c92e254a26154a4d2872eaf4dee9df4be282d7 Mon Sep 17 00:00:00 2001 From: lookerZz <1031516901@qq.com> Date: Mon, 21 Sep 2026 00:46:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E4=BA=8EBase=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/database.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/database.py b/core/database.py index 874c6ef..ee23301 100644 --- a/core/database.py +++ b/core/database.py @@ -9,10 +9,13 @@ IP:localhost 2.如果还没开始建库,建库时统一将名称命名为 student_manager。 如果已经建库或在 models 目录写好Base函数,那先别提交分支,不然合并的时候会出问题,后天合库的时候再说。 + +3.在 /models 目录下写数据库对应类时,不要自己写Base = declarative_base(), +直接 from core.database import Base ,否则会出现 Base 不一致的情况,导致数据库无法创建表。 ''' from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import sessionmaker,declarative_base from .config import ( database_connect_user, database_connect_password, @@ -31,3 +34,5 @@ def get_db(): yield db finally: db.close() + +Base = declarative_base() \ No newline at end of file