Forums

Getting errors working with my database, please advise!

Hello! I am using sqlite3 to check on my database.

I have been in the final stages of finishing my web app and have just been using it myself and seeing how the data populates the database. However, when trying to access the database after some data has been logged, I have been getting random errors that end up, what seems to be, destroying the database in the process.

For example, I have finished recording data on the website, then I go to a bash console and type:

sqlite> SELECT * FROM study;

To see all entries in the study table.

I am expecting a result like this:

1|word|27|1|2023-04-06||1|2.5|2023-04-07

It worked for a while, just logging data and checking if its logged correctly, then at some point I got this:

sqlite> SELECT * FROM study;

Error: disk I/O error

I don't know what caused this. I can not imagine that checking on the database while it is being used should cause this, as that would essentially mean all databases can never be checked while being in use?

Anyway, immediately after, I checked the same query again, this time I got:

sqlite> SELECT * FROM study;

Error: database disk image is malformed

I have never gotten these issues in my local development environment, no matter how many times I checked on the database. What is going on?

I ended up having to replace the database with a prior backup. I resumed checking if my app handles the data correctly, again checking via the query after data is logged. Suddenly I got:

sqlite> SELECT * FROM study;

Error: file is not a database

Is there some special kind of rules I have to follow here on the website, like NOT touching the database while it is logging? For what it is worth, as far as I know, Sqlite3 automatically handles access to make sure data doesn't get lost or corrupted. I have never seen this issue on my local copy.

Any advice or background info to what is going on here would be much appreciated.

Thank you for your time.

I'm surprised that SQLite is doing that too, but on PythonAnywhere it's using a networked filesystem, which would make its behaviour different to what it is on your local system. We haven't heard of any data corruption issues resulting from that -- normally the differences manifest as slower performance -- but perhaps it depends on what tools you're using to access it. I'd strongly recommend using MySQL for database stuff on PythonAnywhere -- it performs much better (and, it appears, more reliably) in a production environment.

Thank you. Hmm. Really strange indeed.

I will try going to MySQL but its VERY difficult compared to sqlite. But I will try. Thank you.