question

creditcruncherX avatar image
1 Vote"
creditcruncherX asked azure-cxp-api edited

Migrate Django model to azure web app postgresql wont work

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-webappsazure-webapps-development
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ryanchill avatar image
0 Votes"
ryanchill answered ryanchill commented

@creditcruncherX, 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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ryanchill many thanks for taking the time to reply. I realised my mistake I had left the database connection in the settings.py file to local rather than the the azure server. Changed the settings file and now all working fine.

1 Vote 1 ·

Glad you were able to get squared away @creditcruncherX.

0 Votes 0 ·