1

I am running a Django app in a test environment on my on PC with a sqlite database. Lately I have problems when trying to use my app, because when I perform several actions, at some point the app just gives the error 'database is locked' and I cannot perform any actions what so ever.

I tried several actions I found in How do I unlock a SQLite database? like renaming the database, copying the database and restarting the computer but none of it seems to unlock the database. The only thing I can do then is completely remove the database and create a new one.

The weird thing is that I have no problems altering the database via the shell, or via a different database viewer (like DB browser for SQLite). Only when I try to make changes to the database via my front-end or the admin page I get a 'database is locked' error (I cannot even login on my app). Which makes my suspect that the database is not really locked but something else might be going on.

There are different moments in time when the database gets locked, but I do have a migration that bulk creates about 100 objects, and using this migration will lock the database every time. However, if I don't run the migration, it will also create problems after using the app for a while. Up until now, I tried, but have not been able to, pinpoint the exact action which causes the database to lock. It seems to be a different action at different times.

I hope someone recognizes this problem and can help me.

Dialess
  • 21
  • 2
  • [Not the downvoter] Check this out [OperationalError: database is locked](https://stackoverflow.com/questions/3172929/operationalerror-database-is-locked) – Lemayzeur May 01 '18 at 09:02
  • I tried all that (except for moving to a different database engine, which I would hate to do for my own test environment). Nothing unlocks my database, even not restarting the computer. Calling `db.connections.close_all()` from the shell also doesn't work, because the database is not locked when I access it from the shell. I production we use MySQL which does not have this problem, but I really like to use SQLite for my personal testing, and think it should not be a problem. – Dialess May 01 '18 at 09:12
  • Apparently, your application has a bug and does not close some query or transaction. – CL. May 01 '18 at 09:46
  • Yeah, unfortunately it seems that way :(. I'm mostly wondering how it comes that it is only locked for the front-end application and not for working with the shell. Also wondering why closing my application, restarting the computer, copying the database all don't work in unlocking the database. – Dialess May 01 '18 at 10:12

0 Answers0