2021年3月30日星期二

Django settings: DATABASE_URL is not working

I just created a test application in Heroku so that I can stay in the same Django project, but quickly switch back and forth between connecting to my production database and my testing app database. I created an environment variable on my laptop using export:TEST_DATABASE_URL="...", but even with this below code I am still connected to my production database when I run my Django project on localhost. Does anyone know how i can accomplish this?

# ~~~ PROD SETTINGS ~~~  # DATABASE_URL = os.environ['DATABASE_URL']  # DEBUG = 'False'    # ~~~ TEST SETTINGS ~~~  DATABASE_URL = os.environ['TEST_DATABASE_URL']  DEBUG = 'True'      # tried commenting this code out so it doesn't use the local sqlite file  # DATABASES = { # Use this to use local test DB # todo: prod doesn't havea access to django_session...  #     'default': {  #         'ENGINE': 'django.db.backends.sqlite3',  #         'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),  #     }  # }  

Procfile:

release: python3 manage.py migrate  web: daphne django_project.asgi:application --port $PORT --bind 0.0.0.0 -v2  worker: python3 manage.py runworker channels --settings=django_project.settings -v2  
https://stackoverflow.com/questions/66866522/django-settings-database-url-is-not-working March 30, 2021 at 03:32PM

没有评论:

发表评论