Database for Development Enviroment

Hi All,

I made the perhaps mortal mistake of using Sqlite3 for development, as opposed to starting with Postgres from the get go, obviously, I deployed the application with Postgres using Heroku, and well now I’m stuck with this problem:

Essentially, I have to switch back from Databases, one for the development server, and then change the settings.py to reflect the development.

# This is the DATABASE for production
DATABASES = {
    'default': dj_database_url.config(
        default=env('DATABASE_URL')
    )
}


"""
# This is the old sqlite3 use for development enviroment
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
"""

I’m using windows, and I have set the environmental variable as followed:

set DATABASE_URL="sqlite://../db.sqlite3"

The step above is not working, obviously, I don’t want to be commenting out the settings.py - Does anyone know what can I do to fix this issue?

if I leave the development DB, I’m getting this error:

django.core.exceptions.ImproperlyConfigured: Set the DATABASE_URL environment variable

Regards
FCS

Forgive me if I lead you astray, but I also was faced with the task of switching between databases, and came up with a bandaid solution:

If this isn’t what you’re looking for, I apologize!

See docs at GitHub - kennethreitz/dj-database-url: Use Database URLs in your Django Application. for the format of the DATABASE_URL used for sqlite. Notice there are 3 slashes after sqlite:

What I tend to do with settings sf have a development settings file and a deployment settings file, but when the dev stuff gets moved to deployment the settings file isn’t copied. if you’re doing it with git, then put it in the gitignore.

The obvious problem is that if you update the dev with something that needs to be in the deployment settings, then you are going to need to keep track of that… But you don’t have to keep editing the settings file between the two (or more) environments.

Also, if you aren’t using PostgreSQL as your test database, you should be careful not to use any PostgreSQL specific features in your code. One thing that I encountered was using the *fields argument to .distinct() which only works in PostgreSQL, not in Sqlite which I was using for tests. For that reason, I now use the same DB for prod, dev, and test.

2 Likes