0

I have a problem with sqlite3 in django. This is the first time I'm using this.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/home/djangobook/mydb.db',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 324, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 306, in _cursor
    self._sqlite_create_connection()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 296, in _sqlite_create_connection
    self.connection = Database.connect(**kwargs)
OperationalError: unable to open database file

thanks for your help.

10
  • Did you already run syncdb? Commented Jan 11, 2014 at 8:22
  • hi dear. No , what is this? Commented Jan 11, 2014 at 8:23
  • Are you running this as user djangobook? Do you have write access to the given path? Commented Jan 11, 2014 at 8:24
  • @user1788781 syncdb is the command to create the database in your application folder at the same level than manage.py run this in console: python manage.py syncdb Commented Jan 11, 2014 at 8:24
  • yes , I have write access to given path. Commented Jan 11, 2014 at 8:25

3 Answers 3

3

You haven't run syncdb

Into your application folder at the same level than manage.py run this in console:

python manage.py syncdb 

For better understanding of django, follow this tutorial by the way you have to write access to the folder.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you but it's result : python manage.py syncdb --->> "OperationalError: unable to open database file"
3

You need write access to the /home/djangobook/ directory and to the /home/djangobook/mydb.db file (is exists).

If the /home/djangobook/mydb.db file does not exist you need to run python manage.py syncdb as pointed by @user1788781.

3 Comments

thank you but it's result : python manage.py syncdb --->> "OperationalError: unable to open database file"
Ok, so be sure thet the /home/djangobook/ directory exists and your user has write access to /home/djangobook/.
I have root access :(
1

Quick answer from me because there is one other possibility which hit me while playing with a Graphite deployment (graphite's web UI is httpd+django). Even if you have the full path configured, permissions are ok on both the db file and the directory, you might have Selinux Enforcing.

If you need selinux enforcing, sorry, I cannot provide details right now on how to make this setup work, but if it is accidentally enabled just do :

root # getenforce
Enforcing
root # setenforce 0
root # getenforce
Permissive

One tip, to debug this issue deeper and confirm it is an issue related to permissions you could use strace :

$ sudo service httpd stop
$ sudo strace -f service httpd start 2>&1 | tee tmp.log

# strace log could contain something similar to the following:
$ grep mydb.db tmp.log 
.... stat("/home/djangobook/mydb.db", 0x7fff55023b80) = -1 EACCES (Permission denied)
.... open("/home/djangobook/mydb.db", O_RDWR|O_CREAT, 0644) = -1 EACCES (Permission denied)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.