views:

230

answers:

4

I am following the tutorial on the DJango site, which I previsouly did using Windows XP and everything went fine, but on Windows 7 I get the following error:

sqlite3.OperationalError: unable to open database file

I use the following:

python manage.py sql Blog

Does any one have any ideas what might be wrong. The database file is located in C:\Software\Sqlite\Databases\Blog.db

And the relative settings.py or section of is simply:

DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'C:\Software\Sqlite\databases\blog.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

I have also for testing purposes added everyone with full permissions.

But as I say I get the following error:

sqlite3.OperationalError: unable to open database file

Any help is appreciated,

Andrew

A: 

A guess is that the file is actually not in that dir. If you have UAC enabled windows 7 will make it look like the file is at that location (it will show up in windows explorer). However the file is really stored in c:\users\yourusername\AppData\Local\VirtualStore\Software\Sqlite\databases or a similar location.

Zerqent
thanks. It is definately in the C:\Software\Sqlite\ directory
REA_ANDREW
+2  A: 

I don't think you can use a full windows path to access your sqlite database. I've run some tests here and the only way I could use a sqlite3 database on django not in the same directory of the project was using DATABASE_NAME = '../anotherfolder/db.db' (this was located at c:\anotherfolder\ and project was located at c:\mydjangoproject)

ikkebr
That got it. Thank you.
REA_ANDREW
A: 

Have a look at the permissions of the folder. Can your regular user edit files there?

Jeduan Cornejo
+3  A: 

I know this question has already an accepted answer, but I think you missed something. You should use raw strings when your strings contain backslashes:

DATABASE_NAME = r'C:\Software\Sqlite\databases\blog.db'

This is what happens if you don't use a raw string:

>>> print 'C:\Software\Sqlite\databases\blog.db'
C:\Software\Sqlite\databaselog.db
Mark Byers