脱离新手文档使用SQLAlchemy配置sqlite,才发现sqlite的URI指定有点特别.
https://github.com/mitsuhiko/flask-sqlalchemy/issues/469
#Unix/Mac - 4 initial slashes in total engine = create_engine(‘sqlite:////absolute/path/to/foo.db‘) #Windows engine = create_engine(‘sqlite:///C:\\path\\to\\foo.db‘) #Windows alternative using raw string engine = create_engine(r‘sqlite:///C:\path\to\foo.db‘)
注意Windows下sqlite后是三道杠. 因为比较常见的是linux下的配置文档,所以很容易误解为正常的配置就是四道杠. 实际的URI格式应为sqlite:///{$path}.
斜杠有误的话会报错: Unable to open the sqlite database file
原文地址:https://www.cnblogs.com/oDoraemon/p/9577760.html
时间: 2024-10-10 15:44:28