Search code examples
pythondjangodjango-settings

Using external database for user logins in Django


I have a Django application where, in development, I was using the default database (sqlite3, I believe) to store user login info. I had a line in my Dockerfile (which would spin up my app) that would add a user and it would automatically just be stored in the default database.

Now that it's moving to production, it would be a colossal pain to add each user one at a time every time we need to update. From what I read in the documentation, it looked like I just needed to modify my settings.py from

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

to

DATABASES = {
    'default': {
        'NAME': 'name_of_user_table',
        'ENGINE': 'django.db.backends.postgresql',
        'USER': 'username',
        'PASSWORD': 'password'

    }
}

I don't use the login info anywhere else in my code, and I can't find any reference to the database aside from in settings.py. Have I done enough to ensure that it can be connected to the external postgreSQL database of user logins, or is there more I need to do? This is my first Django application and I'm still learning how all of this stuff works.


Solution

  • I don't think there will be any issue.

    The below is the configuration I have been using for a while with postgres.

    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'test_db',
            'USER': 'test',
            'PASSWORD': 'admin@123',
            'HOST': 'localhost',
            'PORT': '5432',
        }
    }
    

    Also if the db is completely new you will need to perform migrations i.e. apply migrations.

    Hope so the above helps