0

I've just configured my remote PostgreSQL database @ Elephant but now I'd like to also set the local PostgreSQL connection in order to make some tests before going online (remote db).

This is my settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '***',  
        'USER': '***',   
        'PASSWORD': '***',   
        'HOST': 'lallah.db.elephantsql.com',  
        'PORT': '5432', 
    }
}

How can I update the settings.py to also let me use the localhost PostgreSQL connection without erasing the elephant configurations?

Thank you!

3
  • Does the localhost server have a replica setup of the remote? If so follow instructions here Multiple databases Commented Nov 1, 2020 at 20:30
  • @AdrianKlaver as far as I know, I didn't set up any replica. In the replica (localhost), can I makemigrations & migrate without disturbing the remote server? Commented Nov 1, 2020 at 20:41
  • 1
    Rather then copying the Django docs, I would suggest you read the information at the link I posted. It covers migrations as well as a lot of other things relative to this. The other option is to create an entirely different settings.py and point at that for local use. Commented Nov 1, 2020 at 21:13

1 Answer 1

1

The most common approach is to have something like local_settings.py in your project that is not a part of production dist (gitignored etc). You can define your local settings there, not only db, but caches, compress options and many more and then override production settings in main settings.py by import:

if DEBUG == True:
    from .local_settings import DATABASES, CACHES # and whatever else you want
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.