7

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

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,
    # ...
}

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...

1
  • all your settings lies in your project's settings.py file Commented Jun 15, 2017 at 7:32

1 Answer 1

13

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.

Sign up to request clarification or add additional context in comments.

8 Comments

That doesn't look quite right to me - I expected OPTIONS to be inside the default dictionary, rather than after it.
Fixed location of Options timeout in code above, as @alasdair noted.
How would a setting look like that makes use of an increased timeout during testing?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.