简体   繁体   English

在 AWS 上部署 Django 网站时出现 SQLite 错误

[英]SQLite error when deploying Django Website on AWS

I'm neewbie here and in programming, so please have some mercy:D I'm making my first Django project with Maximilian Course.我是这里和编程方面的新手,所以请怜悯:我正在用 Maximilian Course 制作我的第一个 Django 项目。 I have made Django blog.我做了Django博客。 I walked through few errors when deploy, but now i have encountered this error after deploy and trying to visit my website on AWS:我在部署时遇到了一些错误,但现在我在部署并尝试访问我在 AWS 上的网站后遇到了这个错误:

Django - deterministic=True requires SQLite 3.8.3 or higher upon running python manage.py runserver

but on debbuging page there is something more: In template /var/app/current/blog/templates/blog/index.html, error at l但在调试页面上还有更多内容:在模板/var/app/current/blog/templates/blog/index.html 中,错误位于 l

and in line 25 this is bolded:在第 25 行,这是加粗的:

{% url 'single_post' slug=all_posts.0.slug %}

all_post is a context variable which is of queryset type. all_post 是一个查询集类型的上下文变量。 Is something wrong with this line?这条线有问题吗? On local machine everything works在本地机器上一切正常

So I found this solution:所以我找到了这个解决方案:

Django - deterministic=True requires SQLite 3.8.3 or higher upon running python manage.py runserver Django - deterministic=True 在运行时需要 SQLite 3.8.3 或更高版本 python manage.py runserver

So i understand it like this:所以我是这样理解的:

  1. In ubuntu terminal i type: sudo apt install python3.10-venv to install envirement在 ubuntu 终端输入: sudo apt install python3.10-venv来安装环境

  2. Then in my Django project in Visual Studio i type python3 -m venv django_my_site to create virtual env然后在 Visual Studio 的 Django 项目中,我输入python3 -m venv django_my_site来创建虚拟环境

  3. Now i click "+" to open this env and type pip3 install pysqlite3 and pip3 install pysqlite3-binary现在我点击“+”打开这个环境并输入pip3 install pysqlite3pip3 install pysqlite3-binary

  4. After that i type python3 -m pip freeze > requirements.txt之后我输入python3 -m pip freeze > requirements.txt

and i get requirements.txt file which looks like that:我得到 requirements.txt 文件,看起来像这样:

asgiref==3.6.0
Django==4.1.4
Pillow==9.3.0
pysqlite3==0.5.0
pysqlite3-binary==0.5.0
sqlparse==0.4.3
  1. I have added also 3 lines in settings.py:我还在 settings.py 中添加了 3 行:

     __import__('pysqlite3') import sys sys.modules['sqlite3'] = sys.modules.pop('pysqlite3') DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', } }
  2. After that i pack once more all necessary folders and files of the project.之后,我再次打包项目的所有必要文件夹和文件。

  3. In AWS in application versions I upload zip once more and deploy.在 AWS 的应用程序版本中,我再次上传 zip 并部署。

  4. I rebooted instances and server status is healthy, but still the error with sqlite occure.我重新启动了实例,服务器状态正常,但仍然出现 sqlite 错误。

Some interesting parts of log file:日志文件中一些有趣的部分:

2023/01/02 15:10:03 [warn] 344#344: *157 using uninitialized "month" variable while logging request, client: 192.155.90.118, server: , request: "\00\85\00\00\81\A0cw\9BP\A3\F8U[Z0\EB\A0=\8Ba\CC!\F8ؼ\DD\FB\C9\C0"
2023/01/02 15:10:03 [warn] 344#344: *157 using uninitialized "day" variable while logging request, client: 192.155.90.118, server: , request: "\00\85\00\00\81\A0cw\9BP\A3\F8U[Z0\EB\A0=\8Ba\CC!\F8ؼ\DD\FB\C9\C0"
2023/01/02 15:10:03 [warn] 344#344: *157 using uninitialized "hour" variable while logging request, client: 192.155.90.118, server: , request: "\00\85\00\00\81\A0cw\9BP\A3\F8U[Z0\EB\A0=\8Ba\CC!\F8ؼ\DD\FB\C9\C0"

Jan  2 18:11:17 ip-172-31-87-96 web: create_deterministic_function("django_date_extract", 2, _sqlite_datetime_extract)
Jan  2 18:11:17 ip-172-31-87-96 web: django.db.utils.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher
Jan  2 18:14:34 ip-172-31-87-96 web: Invalid HTTP_HOST header: '54.147.47.55'. You may need to add '54.147.47.55' to ALLOWED_HOSTS.

all LOG file:所有日志文件:

https://files.fm/f/27h4mjf9t https://files.fm/f/27h4mjf9t

LINK TO MY REPOSITORY:链接到我的存储库:

https://github.com/Stanotech/my_site.git https://github.com/Stanotech/my_site.git

some of the settings from settings.py: settings.py 中的一些设置:

from pathlib import Path
from os import getenv


ALLOWED_HOSTS = [
    getenv("APP_HOST")
]


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog'
]

ROOT_URLCONF = 'my_site.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            BASE_DIR / "templates"

        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'my_site.wsgi.application'

__import__('pysqlite3')    
import sys    
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_ROOT = BASE_DIR / "staticfiles"
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    BASE_DIR / "static"
]

MEDIA_ROOT = BASE_DIR / "uploads"
MEDIA_URL = "/user-media/"

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

SESSIONS_COOKIE_AGE = 9999  

did you try to setup envirement to use python 3.7您是否尝试设置环境以使用 python 3.7

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 AWS 上部署 Django 网站时出现 SQLite 问题,无法正确安装 pysqlite - problem with SQLite when deploying Django Website on AWS, cant properly install pysqlite ModuleNotFoundError:将 Django 应用程序部署到 AWS EB 时没有名为“application”的模块 - ModuleNotFoundError: No module named 'application' when deploying Django app to AWS EB 错误:在 AWS Beanstalk 上部署 web 应用程序时出现 ResolutionImpossible 错误 - ERROR: ResolutionImpossible error when deploying web application on AWS Beanstalk Django 'ModuleNotFoundError:部署到 Elastic Beanstalk 时没有名为'blog/wsgi' 的模块,以及'连接到上游时出错' - Django 'ModuleNotFoundError: No module named 'blog/wsgi' when deploying to Elastic Beanstalk, as well as 'Error while connecting to Upstream' 部署到 AWS 时找不到 Platfrom 挂钩 - Platfrom hooks not found when deploying to AWS 部署到 AWS amplify 时出现构建错误 - Building error while deploying to AWS amplify AWS Cloudfront 错误? 部署时失效的最大次数? - AWS Cloudfront error? invalidation max times while deploying? 如何从 AWS EB 下载更新的 sqlite 数据库? (Django 应用程序) - How to download updated sqlite Database from AWS EB? (Django app) 部署到云运行时出现云构建错误 - Cloud build error when deploying to cloud run 将 Laravel 应用程序部署到 AWS Elastic Beanstalk 时出现“403 Forbidden”错误 - Getting a '403 Forbidden' error on deploying a Laravel application to AWS Elastic Beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM