Bad Request (400) can't connect to postgresql

kobbob 0 Reputation points
2023-05-11T08:25:17.1266667+00:00

Hi,

I'm following this tutorial to deploy a django (python), postgreSQL & react app to azure: https://learn.microsoft.com/en-us/azure/app-service/tutorial-python-postgresql-app?tabs=django%2Cwindows&pivots=deploy-portal

The deployment has been successful, but I am now running into issues at the SSH Session stage whilst trying to connect to my database.

I'm currently getting 'Bad gateway (400)' when trying to go live, and the following messages after trying to migrate in the SSH session:

django.db.utils.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address
        Is the server running on that host and accepting TCP/IP connections?
Azure Database for PostgreSQL
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,178 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2023-05-12T05:00:48.7266667+00:00

    Hi @kobbob

    Just to confirm, you're running into this issue at step 4. Generate database schema. And you get this error when you execute python manage.py migrate.

    Looking at the error message, it seems the application looking for the database at localhost. At the SSH terminal, confirm that AZURE_POSTGRESQL_CONNECTIONSTRING is properly set to the PostgreSQL server that was created with the wizard. The manage.py script uses this environment variable to update the managed database.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.