🐛 Bug: Fix the bug where the database cannot be automatically created when it does not exist
Browse files
main.py
CHANGED
@@ -31,6 +31,9 @@ async def create_tables():
|
|
31 |
@asynccontextmanager
|
32 |
async def lifespan(app: FastAPI):
|
33 |
# 启动时的代码
|
|
|
|
|
|
|
34 |
await create_tables()
|
35 |
|
36 |
TIMEOUT = float(os.getenv("TIMEOUT", 100))
|
|
|
31 |
@asynccontextmanager
|
32 |
async def lifespan(app: FastAPI):
|
33 |
# 启动时的代码
|
34 |
+
if not os.path.exists("stats.db"):
|
35 |
+
# 如果数据库文件不存在,创建它
|
36 |
+
open("stats.db", 'a').close()
|
37 |
await create_tables()
|
38 |
|
39 |
TIMEOUT = float(os.getenv("TIMEOUT", 100))
|