问题
I'm trying to connect to a sqlite-database file in a python 3.3 application on a windows 7 x64 machine. To do so, the documentation states:
# 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')
I would like to use the absolute path, what is the windows-equivalent to sqlite:////absolute/path/to/foo.db
? The database is stored in C:/Users/Username/AppData/Roaming/Appname/mydatabase.db
.
Any help is appreciated!
回答1:
On Windows it's a bit tricky, because you have to escape the backslashes:
sqlite:///C:\\path\\to\\database.db
Also, as Windows doesn't have the concept of root
and instead uses drives, you have to specify absolute path with 3 slashes:
sqlite:///C:\\Users\\Username\\AppData\\Roaming\\Appname\\mydatabase.db
来源:https://stackoverflow.com/questions/19260067/sqlalchemy-engine-absolute-path-url-in-windows