Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I know there are a lot of questions floating around there relating to similar issues, but I think I have a specific flavor which hasn't been addressed yet. I'm attempting to create my local postgresql database so that I can do local development in addition to pushing to Heroku.

I have found basic answers on how to do this, for example (which I think is a wee bit outdated):

'#DATABASES = {'default': dj_database_url.config(default='postgres://fooname:barpass@localhost/dbname')}'

This solves the "ENGINE" is not configured error. However, when I run 'python manage.py syncdb' I get the following error:

 'OperationalError: FATAL:  password authentication failed for user "foo"
 FATAL:  password authentication failed for user "foo"'

This happens for all conceivable combinations of username/pass. So my ubuntu username/pass, my heroku username/pass, etc. Also this happens if I just try to take out the Heroku component and build it locally as if I was using postgresql while following the tutorial. Since I don't have a database yet, what the heck do those username/pass values refer to? Is the problem exactly that, that I need to create a database first? If so how?

As a side note I know I could get the db from heroku using the process outlined here: Should I have my Postgres directory right next to my project folder? If so, how?

But assuming I were to do so, where would the new db live, how would django know how to access it, and would I have the same user/pass problems?

Thanks a bunch.

share|improve this question
    
Can you post your entire settings.py? –  Burhan Khalid Jun 11 '13 at 4:06
    
As I remember, for nix OSes you must have for initial at least user named postgres for acess to postgres DB. My experience with PG is limited by Win, Ubunru and CentOS. Try to execute pg_ctl status. Then see if your OS is accepted calls via TCP protocol to Postgres; next, check postgres config pg_hba.conf for acceptable addresses. And so on. Simplest way is to ask Google: "PostgreSQL" [YourOSName] And yes, python no any relations to PG as for other DBMS. –  Abelisto Jun 11 '13 at 4:18
add comment

1 Answer

up vote 4 down vote accepted

Assuming you have postgres installed, connect via pgadmin or psql and create a new user. Then create a new database and with your new user as the owner. Make sure you can connect via psql with the new user into to the database. you will then need to set up an env variable in your postactivate file in your virtualenv's bin folder and save it. Here is what I have for the database:

export DATABASE_URL='postgres://{{username}}:{{password}}@localhost:5432/{{database}}'

Just a note: adding this value to your postactivate doesn't do anything. The file is not run upon saving. You will either need to run this at the $ prompt, or simply deactivate and active your virtualenv.

Your settings.py should read from this env var:

DATABASES = {'default': dj_database_url.config()}

You will then configure Heroku with their CLI tool to use your production database when deployed. Something like:

heroku config:set DATABASE_URL={{production value here}}

(if you don't have Heroku's CLI tool installed, you need to do it)

If you need to figure how exactly what that value you need for your production database, you can get it by logging into heroku's postgresql subdomain (at the time this is being written, it's https://postgres.heroku.com/) and selecting the db from the list and looking at the "Connection Settings : URL" value.

This way your same settings.py value will work for both local and production and you keep your usernames/passwords out of version control. They are just env config values.

share|improve this answer
    
Thanks for the help David. I was able to do the first step following: cyberciti.biz/faq/howto-add-postgresql-user-account. Could you post an example of setting up the env variable, what it should be, and how to make settings.py read from it? I'm a bit confused on that end. –  John Lucas Jun 11 '13 at 14:08
    
@JohnLucas I have changed my answer to try and address your questions. Please let me know if you need more help. –  David S Jun 11 '13 at 15:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.