Migrate Django model to azure web app postgresql wont work

Martin Hall 11 Reputation points
2021-05-27T06:44:26.727+00:00

I have a django web app which is working fine on azure. I can see that it has loaded postgresql from the requirements.txt. However, when i try to makemigrations through azure ssh for the database it will not work and will not load postgresql and i get the following error; File "/opt/python/3.7.9/lib/python3.7/site-packages/psycopg2/init.py", line 127, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: 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?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,530 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Ryan Hill 24,546 Reputation points Microsoft Employee
    2021-05-28T04:42:47.483+00:00

    @Martin Hall , Postgresql doesn't run from the app service. You will have to create a cloud instance to host your service. That's why your command is failing. There is a Deploy Python with PostgreSQL tutorial that I encourage you to review. It contains instructions on how to easily create an Azure PostgreSQL instance, configure your app service to use, and applying migrations through SSH. Feel free to comment below if you're followed the tutorial already or have further questions about this issue.