5

This may be the strangest problem in my 4 years with Django.

My site is working alright locally. In production environment it also runs fine, except, when I try to access the admin site, I get a server error which is an "OperationalError: unable to open database file" in the Apache error log.

The DB file is world writable and the path in the settings are absolute. The production environment is Ubuntu Lucid / Python 2.6 / Sqlite3. I tried both with Django 1.2.4 and 1.3 beta.

The weird part is, I can syncdb on server. It creates the tables and the admin user. I can access the site without problem. I can run shell and create content within python prompt. The site is browsable. It is only when I access admin, I get this error.

I have no basis left for any reasoning. Any help is greatly appreciated.

ps: The error is raised at Apache level, not from Django. The Django traceback is in Apache error log, which reads DatabaseError: unable to open database file.

2
  • Are you sure all your models are the same version like in the database? I had a similar problem once and I didn't realized it in the beginning because I used this model very seldom on my normal page. But the admin will open all of them at once. Commented Jan 31, 2011 at 9:57
  • i couldn't find any problem with models. i can access the admin site locally anyway. also, if it was models, i would get a different error, not cannot open database file. so it must be something else i think. thanks. Commented Jan 31, 2011 at 10:46

2 Answers 2

2

A stupid guess.

Which user is running apache?

I know it's strange that the rest of the site works, but double-check your sqlite db is reachable and read-writable from the user Apache is running as!

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

3 Comments

yes, thanks! i changed the owner group for the whole directory tree to www-data, which is apache, and it worked. strange that i'd already given 777 permission to the sqlite database file but it didn't work. thanks.
Happy to hear good news. Maybe the file was 777, but one (or more) directory in the path was not allowing the apache user to reach the file!
I know that is an old question but for completeness: python sqlite module requires write access to the directory containing the database file.
1
sudo chown www-data /var/www/yourproject/db.sqlite3

this will do the trick(set the user to Apache)

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.