My postgres databse keeps the value postgres for NAME, USER, PASSWORD even when I create new db and new user. It seems that no matter what I do, I cannot alter it.
I use django and an ubuntu droplet.
Steps to reproduce: I add new user, give it admin rights, ensure OpenSSH is open.
Logged as the new user and:
Log into a postgres session- `sudo -u postgres psql`
create new db: `CREATE DATABASE new_db;`
Create new user with a password `CREATE USER dbuser WITH PASSWORD 'dbpsw';`
Alter the roles and grant it all priviliges.
verify connection:
\c new_db
Yet, if I go the bash and retreive the values of the postgres database, Yet, my database stays the same:
NAME = postgres
Password = postgres
User = postgres
>>> DATABASES
{'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'postgres', 'USER': 'postgres', 'PASSWORD': 'postgres', 'HOST': 'localhost', 'PORT': 5432, 'ATOMIC_REQUESTS': False, 'AUTOCOMMIT': True, 'CONN_MAX_AGE': 0, 'CONN_HEALTH_CHECKS': False, 'OPTIONS': {}, 'TIME_ZONE': None, 'TEST': {'CHARSET': None, 'COLLATION': None, 'MIGRATE': True, 'MIRROR': None, 'NAME': None}}}
Any advice as how I can modify and enforce the new databse and user would be highly appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi there,
It sounds like that the issue you’re seeing is related to the Django settings file itself rather than the Postgres configuration. The Django settings file might still contains the default configuration for the PostgreSQL database. You should update your Django settings to use the new database and user you created.
To do that, open your Django project’s settings file, typically found in
my_project/settings.py
. Locate theDATABASES
dictionary and change the values accordingly:After updating the settings file, you should restart your Django development server to apply the changes. If you’re using a production server like Gunicorn or uWSGI, you’ll need to restart the server as well.
After updating the settings and restarting the server, Django should use the new database and user for all database operations.
Let me know how it goes!
Best,
Bobby