# Am I building db.sqlite3 or postgres?

**URL:** <https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463>\
**Category:** Using Django\
**Created:** [February 5, 2021, 3:13pm UTC](https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463 "2021-02-05T15:13:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drone4four](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/drone4four/32/3072_2.png) [@Drone4four](https://forum.djangoproject.com/u/Drone4four)\
**Post date:** [February 5, 2021, 3:13pm UTC](https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463/1 "2021-02-05T15:13:51Z")

</div>

I’m working on one of my first Django projects. I am deploying to Heroku.

Following the doc titled ‘[Concurrency and Database Connections in Django](https://devcenter.heroku.com/articles/python-concurrency-and-database-connections#limit-connections-with-pgbouncer)’, I just added the pgbouncer buildpack with: `$ heroku buildpacks:add heroku/pgbouncer`. The build log includes this:

> …  
> remote: -----\> No change in requirements detected, installing from cache  
> remote: -----\> Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2  
> remote: -----\> Installing SQLite3  
> remote: -----\> Installing requirements with pip  
> remote: -----\> pgbouncer app detected  
> remote: Using pgbouncer version: 1.14.0  
> …

I’m wondering about the third line there because my Django project is already configured with a PostgreSQL db populated with some data. When I navigate to my web app, the PostreSQL db data is still being served (which is what I actually prefer). So does this mean that the buildpack output about SQLite3 is inaccurate? Was SQLite installed or not?

Lines 93-97 of my `settings.py`, include this:

```
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },
}

```

Below that at lines 122-123 of `settings.py`, Postgres is called:

```
db_from_env = dj_database_url.config(conn_max_age=20, ssl_require=True)
DATABASES['default'] = dj_database_url.config(conn_max_age=20, ssl_require=True)

```

---

<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:** [February 5, 2021, 3:25pm UTC](https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463/2 "2021-02-05T15:25:35Z")

</div>

So the short answer to your question is that, yes, you are loading the sqlite libraries, _and_ you are _using_ PostgreSQL.

Remember that the settings.py file is just Python code. So you’re setting a variable named `DATABASES` in line 93, and then changing its value at line 123.

I’m guessing you could remove lines 93-97, since you’re going to be defining your `DATABASES` variable in line 123.

Also, unless something else is going on that you haven’t provided here, line 122 isn’t doing anything for you and likely can be deleted as well.

---

<div class="post-metadata">

**Author:** ![Drone4four](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/drone4four/32/3072_2.png) [@Drone4four](https://forum.djangoproject.com/u/Drone4four)\
**Post date:** [February 5, 2021, 5:28pm UTC](https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463/3 "2021-02-05T17:28:49Z")

</div>

Thank you, KenWhitesell, for your help and guidance so far.

> [@KenWhitesell](#):
>
> I’m guessing you could remove lines 93-97, since you’re going to be defining your `DATABASES` variable in line 123.

I need SQLite for testing locally and Postgres for my project deployed on Heroku. So I need both. My next step is to declare both configuration variables in separate `settings.py`, one `settings.py` for testing locally and one for production remotely. I have already begun working on that as described in Casey Faist’s tutorial: [From Project to Productionized with Python | Heroku](https://blog.heroku.com/from-project-to-productionized-python)

> [@KenWhitesell](#):
>
> Also, unless something else is going on that you haven’t provided here, line 122 isn’t doing anything for you and likely can be deleted as well.

Say I comment out the first line like this:

```
    # db_from_env = dj_database_url.config(conn_max_age=600, ssl_require=True)
    DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)

```

Then my local dev server chokes with this traceback:

> ImproperlyConfigured at /  
> settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.  
> …

Say I reverse the comment, so that the first line is active and the second line is commented out:

```
db_from_env = dj_database_url.config(conn_max_age=600, ssl_require=True)
# DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)

```

…then the traceback disappears and is resolved.

According to Heroku doc linked to in my original post, it requires:

`DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)`

Which is the problem. So which line do I need?

---

<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:** [February 5, 2021, 6:56pm UTC](https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463/4 "2021-02-05T18:56:18Z")

</div>

Looking at the docs for [dj\_database\_url](https://pypi.org/project/dj-database-url/), it looks like the `DATABASES` line should be the only one you need. If it’s failing in your local dev environment, then I would assume that it’s because you’re not setting your environment variables correctly.

---

<div class="post-metadata">

**Author:** ![Drone4four](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/drone4four/32/3072_2.png) [@Drone4four](https://forum.djangoproject.com/u/Drone4four)\
**Post date:** [February 5, 2021, 7:36pm UTC](https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463/5 "2021-02-05T19:36:58Z")

</div>

To confirm: You are saying that this is the correct line:

```auto
DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)

```

As well as these two lines:

```auto
django_heroku.settings(locals())
del DATABASES['default']['OPTIONS']['sslmode']

```

And the reason why Django won’t start now (KeyError) is because of misconfigured environment variables (my local virtual environment)?

---

<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:** [February 5, 2021, 8:53pm UTC](https://forum.djangoproject.com/t/am-i-building-db-sqlite3-or-postgres/6463/6 "2021-02-05T20:53:04Z")

</div>

> [@Drone4four](#):
>
> To confirm: You are saying that this is the correct line:
> 
> ```auto
> DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
> 
> ```

I’m saying that the referenced documentation is saying that that’s all that is necessary.

> [@Drone4four](#):
>
> As well as these two lines:
> 
> ```auto
> django_heroku.settings(locals())
> del DATABASES['default']['OPTIONS']['sslmode']
> 
> ```

I don’t believe I’ve said anything about those two lines - that’s what you’ve reported in your other post as a solution to a different problem.

> [@Drone4four](#):
>
> And the reason why Django won’t start now (KeyError) is because of misconfigured environment variables (my local virtual environment)?

You have not posted a KeyError message in this thread. I’m going to assume you’re referring to this snippet:

> [@Drone4four](#):
>
> ImproperlyConfigured at /  
> settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.  
> …

See the referenced docs for [dj\_database\_url](https://github.com/jacobian/dj-database-url) for the environment requirement (DATABASE\_URL) for using the `.config` method. Verify that that settings has been made and is correct for your local dev environment.
