3

After a electrical failure my network database having problems

I open my login page by running the program but after, the username and password are no longer recognized

I get the error

Exception Type: DatabaseError
Value Exception: database is locked

and my function :

def main_page(request):
    state = ""
    username = password = ''
    if request.POST:
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)

The problem comes from this line : user =....

How can I fix this ?

ניר
  • 1,204
  • 1
  • 8
  • 28
Patrice
  • 209
  • 1
  • 4
  • 15
  • This is not a Django problem. This is a Sqlite problem. See [this question](http://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database) – Taylan Aydinli Mar 10 '15 at 09:06
  • For me the problem was NFS and found a solution here: https://stackoverflow.com/a/6366752/8826047 – Sona Pochybova Apr 09 '21 at 11:57

1 Answers1

9

From Django doc:

SQLite is meant to be a lightweight database, and thus can’t support a high level of concurrency. OperationalError: database is locked errors indicate that your application is experiencing more concurrency than sqlite can handle in default configuration. This error means that one thread or process has an exclusive lock on the database connection and another thread timed out waiting for the lock the be released.

Python’s SQLite wrapper has a default timeout value that determines how long the second thread is allowed to wait on the lock before it times out and raises the OperationalError: database is locked error.

If you’re getting this error, you can solve it by:

  • Switching to another database backend. At a certain point SQLite becomes too “lite” for real-world applications, and these sorts of concurrency errors indicate you’ve reached that point.
  • Rewriting your code to reduce concurrency and ensure that database transactions are short-lived.
  • Increase the default timeout value by setting the timeout database option
geckon
  • 8,316
  • 4
  • 35
  • 59
Seyeong Jeong
  • 10,658
  • 2
  • 28
  • 39
  • 3
    I have just a question. Could you tell me why, before this electric breakdown, It worked perfectly...with sqlite – Patrice Mar 10 '15 at 09:15
  • Perhaps [this question](http://stackoverflow.com/questions/151026/how-do-i-unlock-a-sqlite-database) would answer your question as @vape suggested above. – Seyeong Jeong Mar 10 '15 at 09:21