Forums

SQLite Database not found

Hey all! I am currently using a SQLite3 Database in my website and the CS50 SQL library in my program. I have one folder that contains my app.py (am using a Flask app) and my test.db. With the CS50 library, the program will not load. I am getting the error "RuntimeError: does not exist: test.db". Why could this be? It is focusing on this line of code: db = SQL("sqlite:///test.db")

If anybody could help me, that would be great. Thanks!

Use two slashes instead of 3

Have a look at our help page about using relative and absolute paths here: http://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/

hi did you manage to resolve this? I tried using absolute path as well as using 1,2 ,3 slashes but couldnt get it to work

The resolution is to make sure that you're using the full path to a database file that exists. When you're using the absolute path to a sqlite database, you will have 3 slashes at the start - the first 2 are part of the protocol (sqlite://) and the last one is the first slash in the absolute path (for example, /home/registrashens/dbs/db1.sqlite) so that would end up being sqlite:///home/registrashens/dbs/db1.sqlite

hi i am using db = SQL("sqlite:///home/registrashens/cs50final/fitness.db") which is the absolute path to the databse however, i still have this issue RuntimeError: does not exist: home/registrashens/cs50final/fitness.db Thank you for the detailed response, I am sorry for the trouble.

In that case, perhaps the SQL library you are using does not take the database address in that form. Check the documentation of the library to see how you are supposed to specify the database.

Same problem. Did you solve this?

Hard do give any other advice than the one Glenn gave above.

how can i access the sqlite3 db from outside for maintaining the db?

You can use the CLI: https://sqlite.org/cli.html

I had a similar problem. I am not very savvy but what happened to me was that I had to open a bash console in the virtualenv and type "workon xxxxxx"; xxxxx being the name of the environment. Sorted, the sqlite database started working. Hope it helps.

I also use the CS50 library. Here's how I got it working. Instead of 3 slashes, it's 4. The fourth belongs to the path of the SQLite database. Just like in db = SQL('sqlite:////home/AMC/mysite/final.db'). Hope you find it helpful!

Glad to hear that you made it work!

I was having this issue but got it working. (using cs50 SQL function)

I had to update all of my "db=SQL("sqlite3:///path") to have FOUR slashes at the start, so it looked like:

db=SQL("sqlite3:////home/user....")

See the link to the help page in the 3rd forum post in this topic.

I wouldn't say I like this decision, but the absolute path and 4 slashes helped

Thanks for letting us know!