使用绝对路径,不要使用相对路径。使用相对路径的时候,系统回去找它自己建的库,而不是你的那个。
# 获取当前文件的绝对路径
path = __file__.replace(fr"\{os.path.basename(__file__)}", "").replace("\\\\", "\\")
SQLITE_URI = fr'sqlite:///{path}\fastapi.db'
使用绝对路径,不要使用相对路径。使用相对路径的时候,系统回去找它自己建的库,而不是你的那个。
# 获取当前文件的绝对路径
path = __file__.replace(fr"\{os.path.basename(__file__)}", "").replace("\\\\", "\\")
SQLITE_URI = fr'sqlite:///{path}\fastapi.db'