「Django+AWS(VPC)+Nginx+gunicorn+SQLite3」でdjangoデプロイにおけるエラー。
解決済
回答 7
2022/02/20 21:00
質問内容

お世話になります。

今回、こちらのサイトを開発する上で、 ブログ作成動画などを参考に、下記内容を実現に向けて、進めて参りました。 質問内容に不備不足があるかと思いますが、 ご教示の程お願い致します。

実現したいこと

「Django+AWS+Nginx+gunicorn+SQLite3」でデプロイしたい。

こちらの内容を進める上での下記参考文献を参考に、進めて参りました。

参考文献1:https://qiita.com/Bashi50/items/d5bc47eeb9668304aaa2

参考文献2:https://zenn.dev/k_matsumoto/articles/7b0e4dd7d4e4fc

参考文献3:https://kamatimaru.hatenablog.com/entry/2020/05/28/012131

参考文献4:https://qiita.com/Inoue_Minoru/items/059dea2f63b85c7e8449

長文の為、非常に読みにくいかと思いますが、 現在発生しているエラーの対処に関して、ご存知でしたら、ご教示頂けると幸いです。

現在のエラー内容

(venv) [root@ip-172-31-47-147 e_football2022]# python3 manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/admin/venv/lib64/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/admin/venv/lib64/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/admin/venv/lib64/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/admin/venv/lib64/python3.7/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/admin/venv/lib64/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/admin/venv/lib64/python3.7/site-packages/django/core/management/commands/migrate.py", line 87, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/home/admin/venv/lib64/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/admin/venv/lib64/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/admin/venv/lib64/python3.7/site-packages/django/db/migrations/loader.py", line 274, in build_graph
    raise exc
  File "/home/admin/venv/lib64/python3.7/site-packages/django/db/migrations/loader.py", line 248, in build_graph
    self.graph.validate_consistency()
  File "/home/admin/venv/lib64/python3.7/site-packages/django/db/migrations/graph.py", line 195, in validate_consistency
    [n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
  File "/home/admin/venv/lib64/python3.7/site-packages/django/db/migrations/graph.py", line 195, in <listcomp>
    [n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
  File "/home/admin/venv/lib64/python3.7/site-packages/django/db/migrations/graph.py", line 58, in raise_error
    raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration accounts.0001_initial dependencies reference nonexistent parent node ('auth', '0012_alter_user_first_name_max_length')

エラーの発生経緯


  • 仮想環境におけるSQLiteをバージョンアップ後、「migrate」が下記エラーで実行できず。
  django.core.exceptions.ImproperlyConfigured:SQLite 3.8.3 or later is required (found 3.7.17).

  • djangoバージョンを「2.1」にダウングレードし、上記エラーは解消し、再度「migrate」実行するが、上記「エラー内容」が発生

ソースコード

settings.py

import os
from pathlib import Path
from decouple import config, Csv
import dj_database_url


# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG')

ALLOWED_HOSTS = config('ALLOWED_HOST', default='127.0.0.1', cast=Csv())

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_PORT = 587
EMAIL_USE_TLS = True

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'widget_tweaks', # 追加
    'mainapp', # 追加
    'accounts', # 追加
    'django.contrib.sites', # 追加
    'allauth', # 追加
    'allauth.account', # 追加
    'sass_processor',
    'allauth.socialaccount', # 追加
    'import_export',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'e_football2022.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',
                'mainapp.context.related'
            ],
        },
    },
]

WSGI_APPLICATION = 'e_football2022.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
    'default': dj_database_url.config(
        default=config('DATABASE_URL')
        )
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'ja'

TIME_ZONE = 'Asia/Tokyo'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

SITE_ID = 1
LOGIN_REDIRECT_URL = '/'
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
ACCOUNT_EMAIL_VERIFICATION = 'none'

AUTH_USER_MODEL = 'accounts.CustomUser'
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_USER_MODEL_USERNAME_FIELD = None
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

.env

SECRET_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXX

ALLOWED_HOSTS=XXXXXXXXXXX #AWSパブリックIPアドレス
DEBUG = False
DATABASE_URL=sqlite:///db.sqlite3

EMAIL_HOST_USER=XXXXXXXXXXX@XXXXXX.com
EMAIL_HOST_PASSWORD=XXXXXXXXXXXXXXXXX

.0001_initial.py

import accounts.models
from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0012_alter_user_first_name_max_length'),
    ]

    operations = [
        migrations.CreateModel(
            name='CustomUser',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('email', models.EmailField(max_length=254, unique=True, verbose_name='メールアドレス')),
                ('first_name', models.CharField(max_length=30, verbose_name='姓')),
                ('last_name', models.CharField(max_length=30, verbose_name='名')),
                ('department', models.CharField(blank=True, max_length=30, verbose_name='所属')),
                ('created', models.DateTimeField(default=django.utils.timezone.now, verbose_name='入会日')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
                ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
            ],
            options={
                'verbose_name': 'user',
                'verbose_name_plural': 'users',
            },
            managers=[
                ('objects', accounts.models.UserManager()),
            ],
        ),
    ]

自分で試したこと


当該エラーと多少異なるエラーでしたが、参考文献①を参考に、 「pip3 install django==2.2.4 --user」を実行後、下記エラーが発生。

ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

上記エラーが発生後、参考文献②を参考に、 「vim ~/.bashrc」後、「export PYTHONUSERBASE=/home/root/local」を追加後、 「pip3 install django==2.2.4 --user」を実行したが、上記と同様のエラーが発生。 「--user」を取り除き、「pip3 install django==2.2.4」実行。


djangoのバージョンを上げた為、下記エラーが発生。

  django.core.exceptions.ImproperlyConfigured:SQLite 3.8.3 or later is required (found 3.7.17).

参考文献③を参考に、再度SQLite3をバージョンアップ。


バージョンアップ後、「migrate」実行しても、「エラー内容」は変わらず。 ⇦⇦ 現在ここです。

補足情報

  • Django==2.2.4

  • django-allauth==0.41.0

  • django-environ==0.8.1

  • gunicorn==20.1.0

  • Python3.7.10

  • nginxversion: nginx/1.20.0

回答 7
ベストアンサーを選択すると、解決済みとなります。
nodata
まだ回答がありません
回答
nodata
回答するにはログインが必要です