2

I have built a django website and a part of it is Microsoft authentication link. When I upload the site to azure cloud and click on the "log in" link, I recieve the following error:

OperationalError at /login
database is locked
Request Method: GET
Request URL:    http://bhkshield.azurewebsites.net/login
Django Version: 2.2.2
Exception Type: OperationalError
Exception Value:    
database is locked
Exception Location: /home/site/wwwroot/antenv3.6/lib/python3.6/site-packages/django/db/backends/base/base.py in _commit, line 240
Python Executable:  /usr/local/bin/python
Python Version: 3.6.7
Python Path:    
['/usr/local/bin',
 '/home/site/wwwroot',
 '/home/site/wwwroot/antenv3.6/lib/python3.6/site-packages',
 '/usr/local/lib/python36.zip',
 '/usr/local/lib/python3.6',
 '/usr/local/lib/python3.6/lib-dynload',
 '/usr/local/lib/python3.6/site-packages']
Server time:    Fri, 14 Jun 2019 13:19:22 +0000



I am using sqlite3 (setting.py code piece):

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


I don't understand why I get this error because I don't insert or commit anything to the database.
My website consists only of one page that has a sign in link (4 views: home, contex intialize, login and callback). That's it.

Just to mention, when I run the site locally, everything works. It stops working only after deployment.
Another weird thing is that I have uploaded something like this before to another site on azure and the login worked. For some reason, it doesn't work now and I have no idea why...
Has anyone encountered this type of error and can help?

If you need me to provide more files' content, let me know which files and I will.

ayeka
  • 23
  • 1
  • 5

1 Answers1

0

It seems like a duplication of this question: OperationalError: database is locked.

From the documentation of Django: https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errorsoption

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

I have been developing a Django web app as well, and I chose a Azure SQL Server to be the database of the application. Everything has been working OK.

knl
  • 969
  • 11
  • 35
  • Thank you! I have changed it to Azure SQL and it worked. If anyone else does it as well, in settings.py remember to put `'driver': 'ODBC Driver 17 for SQL Server'` and not `'driver': 'ODBC Driver 13 for SQL Server'` like Microsoft says in the connection string. – ayeka Jun 15 '19 at 10:09
  • @baby_bunny_x3 how wht did you do. I'm facing the same problem – Ahmed Adewale Jan 06 '20 at 14:20