gpt4 book ai didi

Django + Sqlite : database is locked

转载 作者:行者123 更新时间:2023-12-03 16:51:30 25 4
gpt4 key购买 nike

发生电气故障后,我的网络数据库出现问题

我通过运行程序打开我的登录页面,但之后,用户名和密码不再被识别

我得到了错误

Exception Type: DatabaseError
Value Exception: database is locked

还有我的功能:

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)

问题出在这一行:user =....

我该如何解决这个问题?

最佳答案

来自 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

关于Django + Sqlite : database is locked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28958580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com