OperationalError: database is locked(OperationalError:数据库已锁定)
问题描述
我在我的应用程序中做了一些重复的操作(测试它),突然我得到一个奇怪的错误:
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?
推荐答案
来自 django doc:
From django doc:
SQLite 旨在成为一个轻量级的数据库,因此不能支持高并发.OperationalError:数据库已锁定错误表明您的应用程序正在经历比sqlite 默认可以处理配置.这个错误意味着一个线程或进程具有独占性锁定数据库连接和另一个线程超时等待锁将被释放.
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 的 SQLite 包装器有一个默认值确定多长时间的超时值允许第二个线程等待在超时之前锁上引发 OperationalError: database被锁定错误.
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:
- 切换到另一个数据库后端.在某个时刻,SQLite 对于现实世界的应用程序来说变得过于精简",而这些并发错误表明您已经达到了这一点.
- 重写代码以减少并发并确保数据库事务是短暂的.
- 通过设置超时数据库选项来增加默认超时值
http://docs.djangoproject.com/zh/dev/ref/databases/#database-is-locked-errorsoption
这篇关于OperationalError:数据库已锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:OperationalError:数据库已锁定


基础教程推荐
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01