views:

27

answers:

2

I'm in the settings.py module, and I'm supposed to add the directory to the sqlite database. How do I know where the database is and what the full directory is?

I'm using Windows 7.

+1  A: 

The absolute path of the database directory is what you need. For e.g. if your database is named my.db and lives in C:\users\you\ then:

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'C:/users/you/my.db' 

Update

AFAIK you do not have to create the database yourself. The database will be created when you run syncdb. The database can live in any directory you wish. If you want the database to be in you Django project directory just change the path accordingly.

For e.g. let us say your Django project lives in C:\users\you\myproject\. You would then change your settings thus:

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'C:/users/you/myproject/my.db' 
Manoj Govindan
How do I know what the database's name is? Did I have to create the file myself? Where does the database live?
Justin Meltzer
@Justin: updated my answer. See above.
Manoj Govindan
thanks again Manoj! I got it!
Justin Meltzer
A: 

if you don't provide full path, it will use the current directory of settings.py, and if you wish to specify static path you can specify it like: c:/projects/project1/my_proj.db

or in case you want to make it dynamic then you can use os.path module

so os.path.dirname(file) will give you the path of settings.py and accordingly you can alter the path for your database like os.path.join(os.path.dirname(file),'my_proj.db')

Tumbleweed