Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Travis CI for a Django project hosted on Heroku?

I'm trying to setup TravisCI on my Django project.

I'm using Heroku where a classic pattern is to use env var to get postgres database URL:

settings.py

DEBUG = (os.environ['DJ_DEBUG'] == 'True')
import dj_database_url
DATABASES = {'default': dj_database_url.config(conn_max_age=500)}

example of .env file for my local env

DJ_DEBUG=True
DATABASE_URL=postgres://root:[email protected]:5432/captaincook

Now, here is my .travis.yml conf file, that tries to use the locally created db:

language: python

python:
  - 3.5

addons:
  - postgresql: "9.5"

before_install:
  - export DJ_DEBUG=False
  - export DABATASE_URL=postgres://postgres@localhost/travisdb

install:
  - pip install -r requirements.txt

before_script:
  - psql -c "CREATE DATABASE travisdb;" -U postgres
  - python captaincook/manage.py migrate --noinput

env:
  - DJANGO=1.9.10

script: python captaincook/manage.py test --keepdb

The project works everywhere, except when deployed on travis, where I got this Django error: django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

Any idea? Thanks.

like image 240
David D. Avatar asked Mar 10 '23 20:03

David D.


1 Answers

You have a typo: DABATASE_URL instead of DATABASE_URL.

But I suspect that rather than explicitly using export in before_install, you should use the env key:

env:
  - DJ_DEBUG=False
  - DATABASE_URL=postgres://postgres@localhost/travisdb
like image 155
Daniel Roseman Avatar answered Mar 24 '23 00:03

Daniel Roseman