The way I do this is as such:
In settings.py:
import dj_database_url # you'll need this in requirements.txt
DATABASES = {
"default": dj_database_url.config(default='sqlite:///db.sqlite3'),
}
If the DATABASE_URL environment variable is set, as it will be in production (Heroku for me, but you can use a DATABASE_URL env variable anywhere) then use that. Otherwise, fall back to sqlite
Additionally, at the end of settings.py I have:
# Import optional local settings. This must be at the END of this file.
try:
from .local import *
except ImportError:
pass
This way you can override the sqlite database in two ways: you can set the DATABASE_URL environment variable, or you can create a "local.py" file (exclude this from version control via .gitignore) that overrides it and other settings selectively. Why two ways? Primarily because most of the devs on my team are more comfortable managing a local settings file than environment variables.
I use this philosophy for all of my settings that might vary between dev and production, or that contain something I don't want in source control for any other reason.