21👍
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:
~/project/mydata.db
use
/home/user/project/mydata.db
17👍
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:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'epic_project',
...
}
}
when
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”
9👍
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?
- Django: Make JS source maps compatible with staticfiles filename hashing
- Django template img src not working
- Generate Database Schema using Python
- Using Django models in external python script
5👍
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.
- Django REST: Uploading and serializing multiple images
- I have a OneToOne relationship between two objects of the same class in a Django app. Is it possible to enforce the uniqueness of this relationship?
- Cannot get django-debug-toolbar to appear
3👍
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.
- How to properly add entries for computed values to the django internationalization messages file?
- How to maintain different country versions of same language in Django?
- How can I test if my redis cache is working?
- Matplotlib svg as string and not a file
- How to purge all tasks of a specific queue with celery in python?
2👍
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.
settings.py
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.sqlite3',
'NAME' : DATABASE_PATH,
}
}
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.
- Setting Django admin display times to local time?
- Travis: "Got an error creating the test database: permission denied to create database"
0👍
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
-Bill
- Django rest framework create user with password
- Using Django's ORM in a Celery Task
- How to reload new update in Django project with Apache, mod_wsgi?
- CSV file upload from buffer to S3
0👍
If you are specifying a full path to db file and are still having issues, try putting an r before the string.
ie.
r'C:\home\usr\mysite\sqlite3.db'
- Accessing django project in LAN systems
- Email as username in Django
- Multiple sites on Django
- TypeError at /en/ Object of type '__proxy__' is not JSON serializable
0👍
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.