[Fixed]-Django beginner problem: manage.py dbsync


In settings.py are you using a relative path to the sqlite file?

If you are, try changing that to an absolute path.

i.e. instead of:





This can also happen if your database name is the same as your project name. To fix it just change the name of your db e.g. by adding a .db to the NAME. So if your DATABASE NAME in settings.py was ‘epic_project’ change it to ‘epic_project.db’

Long and boring explanation:

If you start your project by running:

django startproject epic_project

your folder structure will be like this:

  • /path/to/epic_project/
    • manage.py
    • epic_project/
      • settings.py

if then in your settings.py you set your database as:

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'epic_project',


python manage.py syncdb 

runs it tries to open or create a sqlite db file at /path/to/epic_project/epic_project, but there is a directory there, so it says “oh ok the path exists already, let’s open it as an sqlite db”, unfortunately for sqlite it’s a directory and not a DB, so it cries and django presents these tears to you as “sqlite3.OperationalError: unable to open database file”



might be a permission problem, does your user have sufficient right to write on the folder? for example if you do

sudo python manage.py syncdb

instead, does it work?


For Google’s sake:

The path to the database must be the full path to the file — not just the directory where the file lives.



I had the same problem on Windows then realized that syncdb would not create the specified folder if it didn’t already exist. I had specified c:/mysite/db/sqlite3.db in settings but the /db/ folder didn’t exist. Created it in terminal then re-ran syncdb successfully.



I had the same problem two days ago. I solved it by setting the ‘NAME’ in the DATABASE dictionary (settings.py) to the absolute path.
For example.


    'default' : {
        'ENGINE' : 'django.db.backends.sqlite3',

here you can set the DATABASE_PATH at the top of the settings.py as such
(Not sure if this will work for windows)

SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir))
DATABASE_PATH = os.path.abspath(os.path.join(PROJECT_PATH, 'your-database-name'))

For Windows you might have to use the replace method. (Not sure .. But you can try it out as follows)

PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir).replace('\\', '/'))

Same goes for the DATABASE_PATH.
PS. Correct me if I am wrong.


Similar to answer from user104264 – different perspective…

Currently following the YouTube tutorial I had the same error. Seems to me while running the manage.py in a virtualenv django project directory …path to virtual env…/django_project/, the database name inside /myapp/settings.py was simply ‘storage.db’ so

(django-v)…path to virtual env project…/django_project/>python manage.py syncdb

created …path to virtual env project…/django_project/storage.db



If you are specifying a full path to db file and are still having issues, try putting an r before the string.




The problem I was running into was a bootstrapping issue where some model lookups were being done at import (outside of any class or function). Per the docs, this is a bad idea.


Leave a comment