26
For me it was for postgres not being started and enabled. So I solved the problem by doing so:
sudo systemctl start postgresql
sudo systemctl enable postgresql
8
Make port default to 5432
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database1',
'USER': 'root',
'PASSWORD': '123456',
'HOST': 'localhost',
'PORT': '5432',
}
}
run the command:
python manage.py runserver 127.0.0.1:8000
- [Django]-How to write a query to get find value in a json field in django
- [Django]-TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
- [Django]-How to make a PATCH request using DJANGO REST framework
6
I just had the same problem and I just had forgotten to start my Postgres. Opening it from my Applications and selecting โOpen psqlโ solved the problem.
- [Django]-How to make a POST simple JSON using Django REST Framework? CSRF token missing or incorrect
- [Django]-How to resize the new uploaded images using PIL before saving?
- [Django]-What's the best way to extend the User model in Django?
5
If you are using Postgresql and developing on a mac then you can use the below command to start Postgresql and it should fix your problem.
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
and to stop it
pg_ctl -D /usr/local/var/postgres stop -s -m fast
- [Django]-Difference between setattr and object manipulation in python/django
- [Django]-Django REST Framework (DRF): Set current user id as field value
- [Django]-Can I use Django F() objects with string concatenation?
5
Try removing host and port:
# settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pass',
}
}
The problem for me was specifying HOST and/or PORT here.
- [Django]-How to write setup.py to include a Git repository as a dependency
- [Django]-Cannot update a query once a slice has been taken
- [Django]-Does get_or_create() have to save right away? (Django)
2
I faced a similar issue and I solved it by changing the value of "HOST": "localhost"
to "HOST": "127.0.0.1"
and it worked.
- [Django]-Sphinx automodule: how to reference classes in same module?
- [Django]-How can I list urlpatterns (endpoints) on Django?
- [Django]-Celery โ run different workers on one server
0
Credit to Addicted above. I checked the log and realized at some point I had upgraded my Postgres version.
$ nano server.log
GNU nano 2.0.6 File: server.log
2020-12-16 02:19:32.273 EST [32414] FATAL: database files are incompatible with server
2020-12-16 02:19:32.273 EST [32414] DETAIL: The data directory was initialized by PostgreSQL version 12, which is not compatible with this version 13.0.
Which can be solved like this.
- [Django]-Django 1.7 migrations โ how do I clear all migrations and start over from scratch?
- [Django]-Get date from a Django DateTimeField
- [Django]-How do I get the object if it exists, or None if it does not exist in Django?
0
no database server is hosted and running locally. For mac, you can turn on a server on port 5432 using the postgres desktop application.
- [Django]-Track the number of "page views" or "hits" of an object?
- [Django]-Can't install via pip because of egg_info error
- [Django]-Django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
0
I Had the same problem but in my case its due to memory shortage.
Due to memory shortage the postgresql was not able to create the file .s.PGSQL.5432 inside /var/run/postgresql/.
So Look for the memory storage and if there is no memory available ,please free some memory and try restarting postgresql service.
- [Django]-Separating form input and model validation in Django?
- [Django]-How do I make many-to-many field optional in Django?
- [Django]-Advantages to using URLField over TextField?
- [Django]-How to access Django's field.choices?
- [Django]-Django plural for templates
- [Django]-Annotating a Sum results in None rather than zero