I have made some repetitive operations in my application (testing it), and suddenly I’m getting a weird error:
OperationalError: database is locked
I've restarted the server, but the error persists. What can it be all about?
I have made some repetitive operations in my application (testing it), and suddenly I’m getting a weird error:
OperationalError: database is locked
I've restarted the server, but the error persists. What can it be all about?
try this command:
From django doc:
http://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errorsoption
In my case, It was because I open the database from SQLite Browser. When I close it from the browser, the problem is gone.
I disagree with @Patrick's answer which, by quoting this doc, implicitly links OP's problem (
Database is locked
) to this:This is a bit "too easy" to incriminate SQlite for this problem. Unless you have a very busy server with thousands of connections at the same second, the reason for this
Database is locked
error is probably more a bad use of the API, than a problem inherent to SQlite which would be "too light". Here are more informations about Implementation Limits for SQLite.Now the solution:
I had the same problem when I was using two scripts using the same database at the same time:
Solution: always do
cursor.close()
as soon as possible after having done a (even read-only) query.Here are more details.
In my case, I had not saved a database operation I performed within the SQLite Browser. Saving it solved the issue.
The practical reason for this is often that the python or django shells have opened a request to the DB and it wasn't closed properly; killing your terminal access often frees it up. I had this error on running command line tests today.
Edit: I get periodic upvotes on this. If you'd like to kill access without rebooting the terminal, then from commandline you can do: