first functionable
This commit is contained in:
11
create_db.py
Normal file
11
create_db.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from api_server import Base, engine
|
||||
|
||||
print("连接数据库 ...")
|
||||
# 从 api_server.py 导入 Base (包含了所有模型) 和 engine (数据库连接)
|
||||
|
||||
print("创建表(如果表不存在)...")
|
||||
# create_all 默认会检查表是否存在 (checkfirst=True),所以重复运行是安全的
|
||||
# 但我们只在需要时手动运行它
|
||||
Base.metadata.create_all(bind=engine, checkfirst=True)
|
||||
|
||||
print("数据表创建成功(或已经存在)。")
|
||||
Reference in New Issue
Block a user