Sunday, 15 July 2012

django - Configure databases section in settings.py for Travis CI -



django - Configure databases section in settings.py for Travis CI -

i have locally running django 1.7 app tests, connecting mysql i configured travis ci repo

question:

i want have have separate database travis , different 1 utilize development.

i tried adding separate settings in settings.py : default (for utilize tests) , development (for utilize in dev boxes); , thought .travis.xml utilize 'default' when ran migrate tasks.

but travis ci errors out error : django.db.utils.operationalerror: (1045, "access denied user 'sajay'@'localhost' (using password: yes)")

i have no thought why trying access development db settings? checked django1.7 docs, googled around no luck.

appreciate help, thanks

my settings.py database section looks below :

databases = { 'default': { 'engine':'django.db.backends.mysql', 'name':'expenses_db', 'user':'root', 'password':'', 'host':'127.0.0.1', 'port':'3306', }, # 'development': { # 'engine':'django.db.backends.mysql', # 'name':'myapp_db', # 'user':'sajay', # 'password':'secret', # 'host':'127.0.0.1', # 'port':'3306', # }, }

note : when 'development' section commented, travis ci build green

my .travis.yml pasted below:

language: python services: - mysql python: - "2.7" env: - django_version=1.7 db=mysql install: - pip install -r requirements.txt - pip install mysql-python before_script: - mysql -e 'create database if not exists myapp_db;' -uroot - mysql -e "grant privileges on *.* 'root'@'localhost';" -uroot - python manage.py migrate script: - python manage.py test

the problem getting because haven't got right database name , settings travis ci. first need separate out settings between travis , project. utilize environment variable called build_on_travis (alternatively can utilize different settings file if prefer).

settings.py:

import os #use next live settings build on travis ci if os.getenv('build_on_travis', none): secret_key = "secretkeyforuseontravis" debug = false template_debug = true databases = { 'default': { 'engine': 'django.db.backends.mysql', 'name': 'travis_ci_db', 'user': 'travis', 'password': '', 'host': '127.0.0.1', } } else: #non-travis db configuration goes here

then in .travis.yml file in before_script sections need utilize same database name in databases settings. have set environment variable in .travis.yml file so:

env: global: - build_on_travis=true matrix: - django_version=1.7 db=mysql

django travis-ci

No comments:

Post a Comment