Merge pull request 'Li yujie' (#18) from LI_YUJIE into main

Reviewed-on: #18
This commit is contained in:
2026-09-21 16:36:15 +08:00
9 changed files with 35 additions and 17 deletions
+13
View File
@@ -0,0 +1,13 @@
from models import *
from core.database import *
from sqlalchemy import create_engine
db_url = "mysql+pymysql://root:123456@127.0.0.1:3306/student_manager?charset=utf8mb4"
engine = create_engine(db_url
,pool_size=50
,echo=True)
Base.metadata.create_all(engine)
db = SessionLocal()
db.commit()
+7 -1
View File
@@ -1 +1,7 @@
from .class_model import Classes
from .class_teacher import ClassTeachers
from .consultant import Consultant
from .employment import Employment
from .score import Score
from .student import Student
from .teacher import Teacher
+1 -1
View File
@@ -3,7 +3,7 @@ from datetime import datetime # 导入datetime模块下的datetime类
from core.database import Base # 从core软件包下的database模块导入Base
class Classes( Base ): # 在python里的名字
__tablename__ = 'classes' # 在数据库中表的名字
__tablename__ = 'class_info_detail' # 在数据库中表的名字
#————创建班级"主键"的字段名————
id = Column( Integer # 声明字段的数据类型是"整数"
, primary_key = True # 声明是"主键"
+6 -6
View File
@@ -12,19 +12,19 @@ from datetime import datetime
class ClassTeachers(Base):
__tablename__ = "class_teachers_info_detail"
id = Column(
BigInteger
Integer
,primary_key=True
,autoincrement=True
,comment='关系')
class_id = Column(
BigInteger
,ForeignKey('class_id')
Integer
,ForeignKey('class_info_detail.id')
,nullable=False
,comment='关联 class_id'
)
teacher_id = Column(
BigInteger
,ForeignKey('teacher_id')
Integer
,ForeignKey("teacher_info_detail.id")
,nullable=False
,comment='关联 teacher_id'
)
@@ -50,4 +50,4 @@ class ClassTeachers(Base):
,nullable=False
,default=0
,comment='逻辑删除'
)
)
+1 -1
View File
@@ -3,7 +3,7 @@ from sqlalchemy import *
from datetime import datetime
from core.database import Base
class Consultant(Base):
__tablename__ = "consultants"
__tablename__ = "consultant_info_detail"
id = Column(Integer, primary_key=True, autoincrement=True, comment="主键")
consultant_no = Column(String(50), unique=True, nullable=False, comment="顾问编号")
+3 -3
View File
@@ -6,11 +6,11 @@ from core.database import Base, engine
# 为了符合三范式,就业表只保存 student_id,不保存学生姓名和班级名称。查询返回时通过关联 students 和 classes 带出学生姓名、班级名称。
class Employment(Base):
__tablename__ = "employments" # 实际数据库的表名字
id = Column(BigInteger, primary_key=True # 主键
__tablename__ = "employment_info_detail" # 实际数据库的表名字
id = Column(Integer, primary_key=True # 主键
, autoincrement=True # 声明是自增主键
,comment="就业信息主键id")
student_id = Column(BigInteger, ForeignKey("students.id") # 外键 -> students.id
student_id = Column(Integer, ForeignKey("student_info_detail.id") # 外键 -> students.id
, nullable=False # 不允许为null
,comment="关联学生id")
employment_status = Column(String(50)
+1 -1
View File
@@ -9,7 +9,7 @@ class Score(Base):
,comment="成绩表序号,自增主键"
)
student_id = Column(Integer
,ForeignKey("student.id")
,ForeignKey("student_info_detail.id")
,nullable=False
,comment="学生学号"
)
+2 -2
View File
@@ -13,11 +13,11 @@ class Student(Base):
, unique = True)
student_name = Column(VARCHAR(50))
class_id = Column(Integer
,foreign_key = 'class_info_detail.id'
,ForeignKey('class_info_detail.id')
)#外键约束 班级表的主键id,存在这个班级,学生表才可以输入
consultant_id = Column(Integer
, ForeignKey('consultant_info_detail.id')
,nullable = True
,foreign_key = 'consultant_info_detail.id'
)#外键约束 顾问表的主键id,存在这个顾问,才可以写入,允许为空
native_place = Column(VARCHAR(100)
,nullable = True)
+1 -2
View File
@@ -5,11 +5,10 @@ from sqlalchemy.dialects.mssql import TINYINT
from core.database import Base
from datetime import datetime
# teachers 老师表 ORM 模型
#字段包括id,teacher_no,teacher_name,phone,email,remark,created_at,updated_at,is_deleted
class Teacher(Base):
__tablename__ = 'teachers_info_detail'
__tablename__ = 'teacher_info_detail'
id = Column(
Integer
, primary_key=True