python - 将站点部署到 Azure 时出现 "OperationalError: database is locked"

标签 python django sqlite azure-web-app-service

我建立了一个django网站,其中一部分是微软身份验证链接。 当我将网站上传到天蓝色云并单击“登录”链接时,我收到以下错误:

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



我正在使用 sqlite3 (setting.py 代码段):

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


我不明白为什么会收到此错误,因为我没有向数据库插入或提交任何内容。
我的网站仅包含一个具有登录链接的页面(4 个 View :主页、contex 初始化、登录和回调)。就是这样。

只是提一下,当我在本地运行该网站时,一切正常。仅在部署后才停止工作。
另一个奇怪的事情是,我之前已经将类似的内容上传到 azure 上的另一个网站并且登录有效。由于某种原因,它现在不起作用,我不知道为什么......
有没有人遇到过此类错误并可以提供帮助?

如果您需要我提供更多文件内容,请告诉我哪些文件,我会提供。

最佳答案

这似乎是这个问题的重复:OperationalError: database is locked .

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

我也一直在开发 Django Web 应用程序,并选择 Azure SQL Server 作为应用程序的数据库。一切都工作正常。

关于python - 将站点部署到 Azure 时出现 "OperationalError: database is locked",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56599656/

相关文章:

java - 如何在Android中编写SQLite execSQL函数?

SQLite 3 : select and count together with group by and without group by

python - 合并 SQL 数据库中的相似条目

python - Pandas 获取月底的数据?

python - 如何在 Linux 中配置 sys.path 变量?

django - Heroku 上的女服务员给出错误

Docker 容器内的 Django + uWSGI/nginx - ImportError : No module named . wsgi

python - 我应该如何在 Google App Engine 项目中导入 django.middleware 类?

python - 多输入多元数据可视化

python - 如何将在不同进程中完成的 SQLite 数据库更改通知进程?