pythonsqlite

Why do I get "unable to open database file" while it works from a unit test?


Why can't I open my SQLite database? A unit test that I pass "/tmp/cer/could.db" can make the database without a problem but when I pass the actual program the same location I get:

OperationalError: unable to open database file

I've tried with an empty database, the database and unit test left out, and with no database at all but got the same error.


Solution

  • Primary diagnosis: SQLite is unable to open that file for some reason.

    Checking the obvious reasons why, and in approximate order that I recommend checking:

    If you're not on the same machine, it's quite possible that the production system doesn't have a /tmp/cer directory. Obvious to fix that first. Similarly, if you're on the same machine but running as different users, you're likely to have permissions/ownership problems. Disk space is another serious gotcha, but less likely. I don't think it's the last three, but they're worth checking if the more obvious deployment problems are sorted. If it's none of the above, you've hit an exotic problem and will have to report much more info (it might even be a bug in SQLite, but knowing the developers of it, I believe that to be quite unlikely).