現在heroku上にdeployしたdjangoアプリのDBをPostgreSQLに変更しようとしています。
やったことは、この記事を参考に
setting fileを以下のように変え、
""" Django settings for personal_portfolio project. Generated by 'django-admin startproject' using Django 2.1.4. For more information on this file, see https://docs.djangoproject.com/en/2.1/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.1/ref/settings/ """ import os import django_heroku # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "省略" # SECURITY WARNING: don't run with debug turned on in production! 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", "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 = "personal_portfolio.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": ["personal_portfolio/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 = "personal_portfolio.wsgi.application" # Database # https://docs.djangoproject.com/en/2.1/ref/settings/#databases from socket import gethostname hostname = gethostname() import dj_database_url db_from_env = dj_database_url.config() DATABASES = { 'default': dj_database_url.config() } ALLOWED_HOSTS = ['*'] # Password validation # https://docs.djangoproject.com/en/2.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/2.1/topics/i18n/ LANGUAGE_CODE = "en-us" TIME_ZONE = "UTC" USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.1/howto/static-files/ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_URL = '/static/' # localでcssを読み込むためのパス(たぶん) STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) django_heroku.settings(locals()) try: from .local_settings import * except ImportError: pass if not DEBUG: SECRET_KEY = os.environ['SECRET_KEY'] # 追加 import django_heroku django_heroku.settings(locals())
下記のステップでdeployしています。
git add -A git commit -m "Change" git push heroku master heroku ps:scale web=1 heroku run python manage.py migrate heroku open
しかしherokuにデプロイ後に、ローカル環境でアプリのhtmlやcssを変えてして上記ステップを踏んでサイトを更新すると、デプロイしたアプリで更新したデータが消えて、全てローカルのものと同じになってしまいました。
どうやらpostgresqlとsqliteの切り替えが上手くいっていないようですが、色々調べてみたり、他のサイトを参考にsettingを書き換えてみましたが同じで、原因がわかりません。
もしおわかりであれば、ご教示頂けると大変助かります。
何卒宜しくお願い致します。
あなたの回答
tips
プレビュー