0

I could use some help figuring out what's the problem with running the development server for one of my django projects. When I run python managy.py runserver, I get an error that ends with this:

OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

Never before has anything like this happened to me while working with Django, so I will be very thankful for every possible solution.

  • 1
    see this answer to similar question https://stackoverflow.com/questions/35455109/cant-run-the-server-on-django-connection-refused – raultedesco Mar 15 '18 at 22:13

2 Answers2

2

Sounds like you are using Postgresql database and it(database) is not answering

Kimmo Hintikka
  • 13,472
  • 7
  • 34
  • 63
0

In the settings.py, search for this code and make sure if it is correct:

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

And Then start postgresql database service:

systemctl start postgresql
systemctl enable postgresql
systemctl status postgresql  # Check if it is running correctly.

UPDATE: If you are familiar with databases, then its better to setup a database server of your own and use credentials to login.

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'databasename',
    'USER': 'databaseuser',
    'PASSWORD': 'userpassword',
    'HOST' : 'localhost',
    'PORT': '',
     }
}
Shameer Kashif
  • 424
  • 3
  • 16
  • If `postgresql` throws back an error about something like *not found* or *not in directory*. Make sure if it is on your system: `sudo apt-get install postgresql postgresql-contrib` – Shameer Kashif Mar 16 '18 at 04:05