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