Using my Django app, I'm able to read from the database just fine. When the application didn't have permission to access the file, it gave me this error:

attempt to write a readonly database

Which made sense. So I edited the permissions on the file, so that the Apache process had write permissions. However, instead of it being able to write, I get this cryptic error:

unable to open database file

If it's useful, here's the entire output:

Request Method: POST
Request URL:    http://home-sv-1/hellodjango1/polls/1/vote/
Exception Type: OperationalError
Exception Value:    
unable to open database file
Exception Location: /usr/lib/pymodules/python2.5/django/db/backends/sqlite3/base.py in execute, line 193
Python Executable:  /usr/bin/python
Python Version: 2.5.2
Python Path:    ['/var/www', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/pymodules/python2.5', '/usr/lib/pymodules/python2.5/gtk-2.0']
Server time:    Sun, 23 Aug 2009 07:06:08 -0500

Let me know if a stack trace is necessary.

link|improve this question

58% accept rate
feedback

3 Answers

up vote 12 down vote accepted

Aha, just stumbled across an article explaining this. Also Django have info on their NewbieMistakes page.

The solution is to make sure the directory containing the database file also has write access allowed to the process.

In my case, running this command fixed the problem:

chown www-data. .
link|improve this answer
feedback

see also http://code.djangoproject.com/wiki/NewbieMistakes#DjangosaysUnabletoOpenDatabaseFilewhenusingSQLite3

link|improve this answer
+1 Yup, that's the one - thanks. You may want to use a text label for your hyperlink instead of posting the full link. – nbolton Jan 17 '10 at 18:54
feedback

The development server needs to be run as the same user who has write perms on the database folder, so if you originally created the database as root, you will need to be root when you run:

python manage.py runserver
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.