Cookiecutter-django: database configuration unclear

Created on 13 Jul 2015  Â·  11Comments  Â·  Source: pydanny/cookiecutter-django

I run into problems when installing. Instruction says

Then, create a PostgreSQL database and add the database configuration using the dj-database-url >app pattern: postgres://db_owner:password@dbserver_ip:port/db_name either:

in the config.settings.common.py setting file,
or in the environment variable DATABASE_URL"

Remarks:
1) I get this error: "FATAL: password authentication failed for user "cookie" "; cookie is my db_owner. For dbserver_ip:port I use 127.0.0.1:5432
2) config.settings.common.py should be config/settings/common.py
3) I used the common.py file; I am curious though how exactly I would set the environment variable DATABASE_URL ; I tried to look it up but do not get clear answers.
4) it seems to implicate one should install dj-database-url ...? More detail please.

Please help.

Most helpful comment

please try to set the environment variable:
DATABASE_URL environment variable

into terminal:

export DATABASE_URL=postgres://cookie:[email protected]:5432/cookieDB

or

export DATABASE_URL="postgres://cookie:[email protected]:5432/cookieDB"

in the same terminal, run:

python manage.py migrate
python manage.py runserver

about question 4:
django-environ use the same api of dj-database-url

All 11 comments

What is the precise value that you used for postgres://db_owner:password@dbserver_ip:port/db_name?

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'cookieDB',
'USER': 'cookie',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}}

DATABASES['default']['ATOMIC_REQUESTS'] = True

2015-07-13 22:27 GMT+02:00 Daniel Greenfeld [email protected]:

What is the precise value that you used for
postgres://db_owner:password@dbserver_ip:port/db_name?

—
Reply to this email directly or view it on GitHub
https://github.com/pydanny/cookiecutter-django/issues/270#issuecomment-121046523
.

I also tried (but get same error):
DATABASES = {
# Raises ImproperlyConfigured exception if DATABASE_URL not in
os.environ
'default': env.db("DATABASE_URL", default="postgres://
cookie:[email protected]:5432/cookieDB"),
}

2015-07-14 16:21 GMT+02:00 mailsietse . [email protected]:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'cookieDB',
'USER': 'cookie',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}}

DATABASES['default']['ATOMIC_REQUESTS'] = True

2015-07-13 22:27 GMT+02:00 Daniel Greenfeld [email protected]:

What is the precise value that you used for
postgres://db_owner:password@dbserver_ip:port/db_name?

—
Reply to this email directly or view it on GitHub
https://github.com/pydanny/cookiecutter-django/issues/270#issuecomment-121046523
.

please try to set the environment variable:
DATABASE_URL environment variable

into terminal:

export DATABASE_URL=postgres://cookie:[email protected]:5432/cookieDB

or

export DATABASE_URL="postgres://cookie:[email protected]:5432/cookieDB"

in the same terminal, run:

python manage.py migrate
python manage.py runserver

about question 4:
django-environ use the same api of dj-database-url

did that, but error remains.

2015-07-14 16:37 GMT+02:00 Fábio C. Barrionuevo da Luz <
[email protected]>:

please try to set the environment variable:
DATABASE_URL environment variable

into terminal:

export DATABASE_URL=postgres://cookie:[email protected]:5432/cookieDB

in the same terminal, run:

python manage.py migrate
python manage.py runserver

about question 4:
django-environ https://github.com/joke2k/django-environ use the same api
https://github.com/joke2k/django-environ/blob/master/environ/environ.py#L315
of dj-database-url

—
Reply to this email directly or view it on GitHub
https://github.com/pydanny/cookiecutter-django/issues/270#issuecomment-121256993
.

Password authentication. Hmmm.... When you created your database, did you also spell correctly the cookie user and mypassword password?

FWIW, I make mistakes on this all the time, which is why for local development I create databases without username and passwords. My thought is that if someone can access my local dev databases without my permission I've got much, much, much bigger things to worry about.

mmh, i tried twice before but will try now without user & pw

2015-07-14 18:07 GMT+02:00 Daniel Greenfeld [email protected]:

Password authentication. Hmmm.... When you created your database, did you
also spell correctly the cookie user and mypassword password?

FWIW, I make mistakes on this all the time, which is why for local
development I create databases without username and passwords. My thought
is that if someone can access my local dev databases without my permission
I've got much, much, much bigger things to worry about.

—
Reply to this email directly or view it on GitHub
https://github.com/pydanny/cookiecutter-django/issues/270#issuecomment-121292247
.

[embarassing:] how do you create a db without username and pw? In psql I
did 'create user with password' so leaving blanks (no ''). Furthermore I
do:
'default': env.db("DATABASE_URL", default="postgres://:@
127.0.0.1:5432/cookieDB"),
and I get now:
django.db.utils.OperationalError: fe_sendauth: no password supplied

2015-07-14 18:25 GMT+02:00 mailsietse . [email protected]:

mmh, i tried twice before but will try now without user & pw

2015-07-14 18:07 GMT+02:00 Daniel Greenfeld [email protected]:

Password authentication. Hmmm.... When you created your database, did you
also spell correctly the cookie user and mypassword password?

FWIW, I make mistakes on this all the time, which is why for local
development I create databases without username and passwords. My thought
is that if someone can access my local dev databases without my permission
I've got much, much, much bigger things to worry about.

—
Reply to this email directly or view it on GitHub
https://github.com/pydanny/cookiecutter-django/issues/270#issuecomment-121292247
.

Solved! Sorry... I messed up Postgres database creation: I did not use ; at the end of psql commands... Now I can continue the setup! Thanks for your help!

When every other environment variable used in this cookiecutter template has a DJANGO_ prefix, it seems to be ambiguous to have the environment variable for database URL as DATABASE_URL. Your thoughts on this @pydanny ?

@lgp171188, please open your observation as a separate issue, as it is arguably unrelated to this issue.

Was this page helpful?
0 / 5 - 0 ratings