我正在尝试连接到 Windows 7 x64 机器上 python 3.3 应用程序中的 sqlite 数据库文件。为此,文档指出:
# sqlite://<nohostname>/<path>
# where <path> is relative:
engine = create_engine('sqlite:///foo.db')
# or absolute, starting with a slash:
engine = create_engine('sqlite:////absolute/path/to/foo.db')
我想使用绝对路径,Windows 中什么是 sqlite:////absolute/path/to/foo.db
?数据库存储在 C:/Users/Username/AppData/Roaming/Appname/mydatabase.db
。
感谢任何帮助!
最佳答案
在 Windows 上它有点棘手,因为你必须转义反斜杠:
sqlite:///C:\\path\\to\\database.db
此外,由于 Windows 没有 root
的概念,而是使用驱动器,因此您必须使用 3 个斜杠指定绝对路径:
sqlite:///C:\\Users\\Username\\AppData\\Roaming\\Appname\\mydatabase.db
关于python - Windows 中的 SQLAlchemy 引擎绝对路径 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19260067/