Question

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

Was it helpful?

Solution

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)

OTHER TIPS

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

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.

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

Reverse the slashes in DATABASE_NAME: from C:\Software\Sqlite\databases\blog.db to C:/Software/Sqlite/databases/blog.db

I am using django 1.4 on Win7 and this was the solution for me - the file doesn't need to exist already

Reversing the slashes in the database name solved the problem for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top