Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 manage.py syncdb? I'm on a mac.

like image 424
bash- Avatar asked Sep 15 '11 12:09

bash-


People also ask

Where is SQLite database stored in Django?

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

Where is SQLite database created?

A SQLite database is a regular file. It is created in your script current directory.

Where is SQLite file located?

The Android SDK provides dedicated APIs that allow developers to use SQLite databases in their applications. The SQLite files are generally stored on the internal storage under /data/data/<packageName>/databases.


1 Answers

In the settings.py file, there is a variable called DATABASES. It is a dict, and one of its keys is default, which maps to another dict. This sub-dict 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' DATABASES = {     '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 manage.py shell. Just follow the steps below:

>>> import settings >>> settings.DATABASES['default']['NAME'] '/Users/brandizzi/Documents/software/netunong/database.db' 

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']) '/Users/brandizzi/Documents/software/netunong/database.db' 
like image 141
brandizzi Avatar answered Sep 29 '22 13:09

brandizzi