bash- bash- - 2 years ago 91
Python Question

Where is the sqlite database file created by Django?

I've got python installed and sqlite is included with it... but where is the sqlite db file path that was created with syncdb
? I'm on a mac.

Answer Source

In the file, there is a variable called DATABASES. It is a dict, and one of its keys is default, which maps to another dict. This subdict has a key, NAME, which has the path of the SQLite database.

This is an example of a project of mine:

CURRENT_DIR= '/Users/brandizzi/Documents/software/netunong'
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': CURRENT_DIR+ '/database.db', # <- The path
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',

You can easily retrieve this value using the Django shell that is accessible running the command python shell. Just follow the steps below:

>>> import settings
>>> settings.DATABASES['default']['NAME']

If the returned value is some relative path, just use os.path.abspath to find the absolute one:

>>> import os.path
>>> os.path.abspath(settings.DATABASES['default']['NAME'])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download