Forums

manage.py dbshell can't detect the sqlite database file location

Hi!

I have Django app with local sqlite database

My "freudigameisen_pythonanywhere_com_wsgi.py" is

path = '/home/freudigameisen/ich_bau'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'ich_bau.settings'

But - if I run the 'python manage.py dbshell' or 'python manage.py dbshell --settings ich_bau.settings'

i've got the wrong path to sqlite database (new empty file was created)

How to run the dbshell correctly ?

Where do you keep your database?

Path to working database is

/home/freudigameisen/dev.db

Database settings is

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": "dev.db",
    }
}

If you want to keep your database file in non-default location, you should provide full path to it in the NAME field.

settings is working good for application

my question is why it is unavailable for dbshell command

it is because you gave a relative path for the database location, and when you run it as a dbshell command, you are probably in a different working directory from the directory for the application. hence the suggestion above to use a full path.