最近在学习flask,使用sqlalchemy的时候遇到了问题,我用的是win10系统,配置文件如下:
class DevelopmentConfig(Config):
DEBUG = True
DATABASE_URI = 'sqlite:////F:/code/python/fishkeeping/fishkeeping/fish.db'
USERNAME = 'admin'
PASSWORD = 'a00123456'
SECRET_KEY = '11f0394a7e0c-4585-af6b-5b4efcf6fd8f'
之后发生了打不开数据库的异常,发现路径被程序修改为了
'C:\F:\code\python\fishkeeping\fishkeeping\fish.db'
试了好几次,发现不管sqlite:////
后面接的是什么,都会在前面加一个C:\
,非常诡异,求解决。
淡淡烟草味2017-05-27 17:41:23
官方文件有交待engine = create_engine('sqlite:///C:pathtofoo.db') # Windows
engine = create_engine('sqlite:///C:pathtofoo.db') # Windows
engine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw string
engine = create_engine(r'sqlite:///C:pathtofoo.db') # Windows alternative using raw string