Am I building db.sqlite3 or postgres?

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’, 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)

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.

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

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

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?

Looking at the docs for 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.

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

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

As well as these two lines:

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)?

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

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.

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

See the referenced docs for 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.