Django + SQLite如何在“数据库被锁定”时增加SQLite超时。发生错误 [英] Django + SQLite how to increase SQLite timeout when "database is locked" error occurs

查看:138
本文介绍了Django + SQLite如何在“数据库被锁定”时增加SQLite超时。发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在得到: django.db.utils.OperationalError:数据库表被锁定错误(哦,男孩儿有很多该问题的副本)所有答案请参阅此页面:

I am getting the: django.db.utils.OperationalError: database table is locked error (an oh boy are there many copies of that question) all of the answers refer to this page:

https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errorsoption

,尽管我了解发生了什么,但我显然并不十分了解Python和Django,无法理解该指令。指令是增加超时时间,例如:

and although I understand what is going on I clearly don't know Python and Django well enough to understand the instruction. The instruction is to increase the timeout like:

'OPTIONS': {
    # ...
    'timeout': 20,
    # ...
}

对于非常小的大脑来说,要准确地理解代码的去向并不是那么容易。有人可以给我更多背景信息吗?我在Django项目中的哪里指定这些选项?不能是通用的Django设置,可以吗?超时听起来像是lika的名称有点笼统……

but it's not so easy for a-bear-of-very-little-brain to understand exactly where that code goes. Can someone give me a bit more context? Where in my Django project do I specify these sort of options? It can't be a general Django setting can it? Timeout sounds lika a bit too general a name for that...

推荐答案

所以,是的,它可以在设置文件中找到,但不是只是直接在设置文件中,但在数据库下(当然)。

So, yes it goes in the settings file but not just directly in the settings file but under DATABASES (of course).

我的数据库部分现在看起来像这样:

My DATABASES part now looks a bit like this:

   DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'OPTIONS': {
            'timeout': 20,  # in seconds
            # see also
            # https://docs.python.org/3.7/library/sqlite3.html#sqlite3.connect
        }
    }

}

似乎可以解决问题。也许这对于其他人来说是显而易见的,也许不是。负担很小的熊并不总是那么容易。

Which seems to have done the trick. Maybe this was obvious for everyone else or maybe not. It's not always so easy for a-bear-of-very-little-brain.

这篇关于Django + SQLite如何在“数据库被锁定”时增加SQLite超时。发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆