My Database is being deleted after each restart of my code. How can I fix it?
Hi, I'm making a discord bot and I want it to have a custom prefix feature. I've decided to use sqlite for it. And it's kind of working, but each time I restart it - all the data from my database is gone.
Why is it happening?
What filename are you using for the database?
This must be a contender for the gold-medalist in the least-specific-questions category.
Your question sounds like this to me:
I've decided to learn to drive, and use a car for it. I'm kinda doing ok so far, but every time I look in my garage, there is no car there.
Why is it happening?
We could spend all day guessing.
Could you tell us please:
- Which operating system,
- What is the file path (including name) of the SQLite that is opened (and then magically disappearing),
- How are you opening it,
- Are you using a wrapper, library, compiled-in SQLite, or something else?
- Can you open the file with another SQLite tool or the CLI? At least before it disappears?
- Have you ever seen the file appear?
We are not politicians, we can't inform public opinion on the skantest of suggestions, we need hard evidence and understanding to form ideas or suggestions.
I'm not willing to make many guesses, or spend much of my day making them, but I do have a couple:
Perhaps you are using :memory: as your database name. Those DBs are assured a lifetime not extending beyond closing the connection.
Perhaps your tables are being created as temporary ones. Without seeing your DDL, this is among the prime candidates.
I could go on, but that's enough guessing for today.
I can play the guessing game too: A transaction was not closed before exiting. I think some language bindings (python?) open a transaction automatically, but leaves it up to the user to commit it.
Does your bot neatly close the database connection when it stops, or is it just crashing ?
When is the database file being deleted, if it is being deleted at all ? In other words, does the database file exist in storage
- while your bot is running ?
- after your bot has stopped ?
If you use the same bot to open a text file in the same folder, and append text to it each time it starts up, do you actually get one additional piece of text every time it starts up ?