在Heroku数据库中设置Django错误

时间:2019-05-27 17:41:53

标签: python django heroku

这是我第一次使用django,我想在heroku中部署它。我收到下一个错误“ config ['DATABASES'] ['default'] = dj_database_url.config(conn_max_age = MAX_CONN_AGE,ssl_require = True) TypeError:config()在我运行

时得到了意外的关键字参数'ssl_require'“
heroku run python manage.py migrate

我已尝试按照本指南进行部署,使本地数据库成为sqlite3和生产postgresql https://medium.com/@BennettGarner/deploying-django-to-heroku-procfile-static-root-other-pitfalls-e7ab8b2ba33b 我实际上想将两个数据库都设置为postgresql,因为我已将其安装在本地计算机上

这是settings.py

import os
import dj_database_url
import dotenv
import django_heroku

DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'crispy_forms',
    'users.apps.UsersConfig',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'myapp.urls'

WSGI_APPLICATION = 'myapp.wsgi.application'


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

DATABASES = {'default': {}}
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Password validation
# https://docs.djangoproject.com/en/2.2/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',
    },
]

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

AUTH_USER_MODEL = 'users.CustomUser' 
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
CRISPY_TEMPLATE_PACK = 'bootstrap4'

django_heroku.settings(locals())

del DATABASES['default']['OPTIONS']['sslmode']

这是.env

DATABASE_URL=sqlite:///db.sqlite3

这是Procfile

web: gunicorn grupo1-llevame.wsgi --log-file -

我希望迁移能够顺利进行,但我没有找到任何建议,因此我决定在这里提出有关如何解决这个问题的建议,这是我第二次使用该网站。

也在运行时

python migrate.py runserver

它显示此错误“ del DATABASES ['default'] ['OPTIONS'] ['sslmode'] KeyError:“ OPTIONS””

1 个答案:

答案 0 :(得分:0)

heroku不允许在生产中使用sqlite。请改用postgresql。