-2

I am trying to deploy my django app on heroku server,i followed the instructions from this website https://devcenter.heroku.com/articles/getting-started-with-python#introduction .it worked fine till , "heroku open" command.When i came to the part where i need to host my database using " heroku run python manage.py syncdb" command , it failed showing the mesage "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?". I tried lots of fixes including the one suggested here Deploying Django app's local postgres database to heroku? and http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html .I tried all the solutions including editing the "listen_address" = '*' and tcpip_socket='true' in postgresql.conf and editing the ipv4 and v6 values in pg_hba.conf to host all all 127.0.0.1 255.255.0.1 trust host all all 10.0.0.99/32 md5 host all all 0.0.0.0/0 .

But none of them worked .I am guessing the problem arises because heroku can not connect to my local postgres server.This is strange because i'm able to access the postgres server via pgadmin.

And also in the django settings.py looks like this

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'django_test', 'USER': 'postgres', 'PASSWORD': '******', 'HOST': 'localhost', # Or an IP Address that your DB is hosted on 'PORT': '5432', } } Do i need to change this and use heroku's database settings instead??

3
  • So the postgres server is located on the heroku server, correct? Commented Sep 25, 2015 at 15:57
  • no its on my local system Commented Sep 25, 2015 at 15:58
  • but if i give the server url of postgres db that i created on heroku(which starts with "postgres//xxxxxxxxxxxxxx", it says can not translate the address Commented Sep 25, 2015 at 16:00

1 Answer 1

1

localhost on the server points to the server not your local machine. The reason why is because the server running your django code will try and resolve the dns name localhost and it has a pointer to 127.0.0.1 which is local to the server resolving that name. That will NOT point to your computer you are working on.

You need to get an instance of postgres on heroku and change HOST: 'xxx.xxx.xxx.xxx to the IP address of your new postgres instance in your django settings.

Sign up to request clarification or add additional context in comments.

3 Comments

if config on my system shows this eth0 Link encap:Ethernet HWaddr fc:aa:14:5f:7b:84 inet addr:192.168.0.101 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::feaa:14ff:fe5f:7b84/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:332469 errors:0 dropped:2 overruns:0 frame:0 TX packets:287358 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 "which i don't think contain my ip address"
No it doesn't. Will be easier to just spin up a postgres instance on heroku or add postgres to your current heroku server.
VOILA , it worked thanks man , i was using the url of postgres ,instead of host...thanks alot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.