Created
November 27, 2013 13:59
-
-
Save ekiara/7676136 to your computer and use it in GitHub Desktop.
SQL Alchemy SQLITE relative path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SQL Alchemy SQLITE relative path | |
# Relative path is the path 'raw' after the three initial slashses | |
e = create_engine('sqlite:///path/to/database.db') | |
e = create_engine('sqlite:///relative/path/here.db') | |
# Absolute path is a slash after the three initial slashses | |
e = create_engine('sqlite:////tmp/absolute_path_database.db') | |
Had trouble with just a string, I had to do this:
db_dir = "../../database/db.sqlite"
print(f'os.path.abspath(db_dir): {str(os.path.abspath(db_dir))}')
SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.abspath(db_dir) # works
# SQLALCHEMY_DATABASE_URI = "sqlite:///" + db_dir # fails
Thanks @valhuber
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you need a step back do 'sqlite:///../tmp/absolute_path_database.db'