Python manage.py migration error in ssh environment

Asked 1 years ago, Updated 1 years ago, 112 views

Working in ssh virtual environment. (Migrate and make migration are done in the first environment outside of ssh.)
python 3.6.8
pip21.3.1
You are using virtualenv.
In postgresql, roles and databases are also created.
DJANGO_SETTINGS_MODULES= microblog.settings.prod
I also configure the module every time I connect to ssh as a destination in .

I'm trying to deploy by creating a site using a study site.
In other site searches, settings.py has created a new folder called settings and is now divided into four files.

dev.py
heroku.py
prod.py
common.py

What is currently stuck is that the environment cannot be migrated.

prod.py, common.py is the database design part.

prod.py

from.common import*

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

ALLOWED_HOSTS = ['*', ]

INSTALLED_APPS+=(
    'gunicorn',
)

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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'Database Name',
        USER: 'Same as database name',
        'PASSWORD': 'Same as database name',
    }
}

common.py

""
Django settings for microblog project.

Generated by 'django-admin startproject' using Django 3.2.8.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

importos

# Build paths inside the project like this: BASE_DIR/'subdir'.
BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print(BASE_DIR)


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY= It's a secret, so Japanese



DATABASES={}

# Application definition

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

    'blog',
]

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='microblog.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.normpath(os.path.join(BASE_DIR, "templates")),
        ],
        'APP_DIRS': True, #False->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',
            ],
        },
    },
]
print(os.path.normpath(os.path.join(BASE_DIR, "templates"))))

WSGI_APPLICATION='microblog.wsgi.application'

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

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilityValidator',
    },
    {
        '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/2.0/topics/i18n/

LANGUAGE_CODE='ja'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

STATIC_URL='/static/'
STATICFILES_DIRS=(
    # mac / : Windows ¥
    os.path.normpath(os.path.join(BASE_DIR, "assets")),
)
STATIC_ROOT=os.path.normpath(os.path.join(BASE_DIR, "static")))

LOGIN_REDIRECT_URL='/'

These two are
/opt/django/microblog/microblog0/microblog/settings/prod.py
is located in the hierarchy of
manage.py is located at It is in the location of .

In this setting, the pip freeze command

asgiref==3.4.1
Django == 3.2.9
psycopg2-binary==2.9.1
pytz==2021.3
sqlparse == 0.4.2
typing-extensions == 3.10.0.2

The above configuration is installed.

If you do python3 manage.py migrate in that state

 raise ImproperlyConfigured("settings.DATABASES is Improperly configured."
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is provisionally configured.Please supply the ENGINE value.Check settings documentation for more details.

The error occurred and suggested that psycopg2-binary might not be installed properly, but it is stuck in the same state after uninstalling and reinstalling.

Please let me know if anyone has ever experienced a similar situation.

python django deployment

2022-09-30 15:43

1 Answers

In conclusion, python manage.py migration was successful, but I don't know why.

I hung up CentOS 7 once and the ssh was disconnected, so I started CentOS 7 again.
Then go in with ssh and go into the virtual environment

Python manage.py migrate

ModuleNotFoundError: No module named 'gunicorn'

appears, which is different from the previous error.
Last time,

django.core.exceptions.ImproperlyConfigured:settings.DATABASES is implemently configured.Please supply the ENGINE value.Check settings documentation for more details. 

Also, the part that was ModuleNotFoundError in VScode, prod.py

INSTALLED_APPS+=(
    'gunicorn',
)

Delete this and use the source tree

commit

push


at the following terminals

git pull

sudo systemctl restart postgresql

python manage.py migrate

You have now migrated.

However, without configuring prod.py for gunicorn, it's popular at first, and

 python manage.py migrate

django.core.exception~~ error occurred

Even if you add gunicorn,
Because django.core.exception~~ error occurred

Why do you do migrate after reconnecting the ssh and configuring export?
The error changed, and I could not understand why migration passed by just correcting it.


2022-09-30 15:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.