# \[settings.py\] How do I change the DB used when project is spun up in ci/cd (github actions)?

**URL:** <https://forum.djangoproject.com/t/settings-py-how-do-i-change-the-db-used-when-project-is-spun-up-in-ci-cd-github-actions/11420>\
**Category:** Django Internals\
**Created:** [January 7, 2022, 1:33am UTC](https://forum.djangoproject.com/t/settings-py-how-do-i-change-the-db-used-when-project-is-spun-up-in-ci-cd-github-actions/11420 "2022-01-07T01:33:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSoup](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/msoup/32/6957_2.png) [@MSoup](https://forum.djangoproject.com/u/MSoup)\
**Post date:** [January 7, 2022, 1:33am UTC](https://forum.djangoproject.com/t/settings-py-how-do-i-change-the-db-used-when-project-is-spun-up-in-ci-cd-github-actions/11420/1 "2022-01-07T01:33:11Z")

</div>

My apologies if this has been answered already. I am trying to figure out how to get Django to use sqlite3 when doing automated tests through github actions, but use mssql when run locally. The reason is because well… I can’t just spin up a mssql server instance in my github actions, or not that I am aware of. Perhaps there is a better solution that gets around this problem to begin with, and I’m all ears.

So far, I’ve tried something like this:

settings.py

```auto
if len(sys.argv) > 2 and sys.argv[2] == "sqlite3":
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }

else:
    DATABASES = { 
        "default": {
            "ENGINE": "mssql",
            ...
        }
}

```

The problem with this approach is that I have to type `python manage.py runserver sqlite3` to get django to connect to it, which I found out the hard way, interferes with a lot of other operations, such as migrate. Is there a best practice that tackles this kind of situation?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 7, 2022, 1:48am UTC](https://forum.djangoproject.com/t/settings-py-how-do-i-change-the-db-used-when-project-is-spun-up-in-ci-cd-github-actions/11420/2 "2022-01-07T01:48:29Z")

</div>

One way to do this would be to set the desired database settings as an environment variable, and test that environment variable in your settings.

For an example of another idea along these lines, see [GitHub - jacobian/dj-database-url: Use Database URLs in your Django Application.](https://github.com/jacobian/dj-database-url)

---

<div class="post-metadata">

**Author:** ![MSoup](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/msoup/32/6957_2.png) [@MSoup](https://forum.djangoproject.com/u/MSoup)\
**Post date:** [January 7, 2022, 5:27am UTC](https://forum.djangoproject.com/t/settings-py-how-do-i-change-the-db-used-when-project-is-spun-up-in-ci-cd-github-actions/11420/3 "2022-01-07T05:27:01Z")

</div>

Thank you for your prompt response. Using environment variables as the trigger point should work nicely. I heard that this should be avoided in production, though. Would you happen to have suggestions for a prod environment?

For completeness, this is the solution I came up with for now. I hope this helps someone else out in the future.

manage.py

```auto
if os.getenv('DB') == "sqlite3":
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        }
    }
else:
    DATABASES = { 
        "default": {
            "ENGINE": "mssql",
            ...
        }
}

```

.env (change sqlite3 to empty string or something else to use production)

```auto
DB="sqlite3"

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 7, 2022, 1:03pm UTC](https://forum.djangoproject.com/t/settings-py-how-do-i-change-the-db-used-when-project-is-spun-up-in-ci-cd-github-actions/11420/4 "2022-01-07T13:03:43Z")

</div>

> [@MSoup](#):
>
> I heard that this should be avoided in production, though.

I’m not sure where you might have heard that. Using environment variables is absolutely one of the most reliable means of managing differences between deployment environments.
