33đź‘Ť
If you want to use a local password less connection then you need to remove the values “HOST”, “PORT” and “PASSWORD”.
With this configuration your connector will try to connect using a unix domain socket which is the only allowed password less connection allowed by default in Postgres
10đź‘Ť
I can think of two possible solutions to this problem.
First, if there is no password for the database, remove the PASSWORD
key. E.g.:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'project_name',
'USER': 'admin',
'HOST': 'localhost',
'PORT': '5432',
}
}
Second, if there is a password for the database, provide it in the PASSWORD
key:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'project_name',
'USER': 'admin',
'PASSWORD': '<YOUR PASSWORD HERE...>',
'HOST': 'localhost',
'PORT': '5432',
}
}
- [Django]-How to test auto_now_add in django
- [Django]-Any thoughts on A/B testing in Django based project?
- [Django]-Simple way to reset Django PostgreSQL database?
1đź‘Ť
Maybe a stupid thing. But for me the problem was that postgres wasn’t actually running. So always check whether it’s running.
In Linux:
sudo service postgresql status
- [Django]-Python/Django debugging: print model's containing data
- [Django]-How do I use Logging in the Django Debug Toolbar?
- [Django]-Django – how to process/clean a field before validation
0đź‘Ť
TO CREATE NEW DATABASE
Open pgAdmin, left click on Servers then right click on PostgreSQL—>Create—>Database. Fill the database name field, let say SCHOOL and save.
TO REGISTER SERVER
Right click on Servers then Register–>Server, fill the Name field with any name of your choice for example admin. Navigate to connection, fill the Hostname/address field with localhost or 127.0.0.1,fill the password field let say 1234 and save password, leave other fields as they are.
image may not be available at the moment
Finally your codes snippet will be like the below one;
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'SCHOOL',
'USER': 'postgres',
'PASSWORD': '1234',
'HOST': 'localhost',
'PORT': '5432',
}
}
- [Django]-Only showing year in django admin, a YearField instead of DateField?
- [Django]-Exclude fields in Django admin for users other than superuser
- [Django]-Django exists() versus DoesNotExist
- [Django]-Django admin – make all fields readonly
- [Django]-Can I make an admin field not required in Django without creating a form?
- [Django]-Auto-reloading of code changes with Django development in Docker with Gunicorn