Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django is "unable to open database file"

after running "python manage.py syncdb" i gett an error saying "unable to open database file".

here is the important part from my settings.py:

DATABASE_ENGINE = 'sqlite3'    # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = 'apps.db'      # Or path to database file if using sqlite3. DATABASE_USER = ''             # Not used with sqlite3. DATABASE_PASSWORD = ''         # Not used with sqlite3. DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3. 

and here are the permissions for "apps.db":

-rw-r--r-- 1 root root 33792 19. Jul 10:51 apps.db 

My django server is called from apache... i don't know if it has to do with the permissions but changing the owner of apps.db to "www-data" did not work either

[edit]

to ensure www-data can access all of this i did the following:

did the following:

chown -R www-data apps rm apps.db su www-data python manage.py syncdb 

but it still does not work :(

like image 773
niklasfi Avatar asked Jul 19 '10 11:07

niklasfi


People also ask

Can not open database file?

Make sure that the folder does not start with the full path to the database files with a number. Check the full path containing the db directory. Make sure that the /tmp directory is globally writable. Make sure that the path to the database specified in settings.py is a complete path.


1 Answers

Solution from NewbieMistakes

Make sure Apache can also write to the parent directory of the database. SQLite needs to be able to write to this directory.

Make sure each folder of your database file's full path does not start with number, eg. /www/4myweb/db (observed on Windows 2000).

If DATABASE_NAME is set to something like '/Users/yourname/Sites/mydjangoproject/db/db', make sure you've created the 'db' directory first.

Make sure your /tmp directory is world-writable (an unlikely cause as other thing on your system will also not work). ls /tmp -ald should produce drwxrwxrwt ....

Make sure the path to the database specified in settings.py is a full path.

like image 181
pass-by-ref Avatar answered Oct 21 '22 10:10

pass-by-ref