views:

265

answers:

3

In Django I am using two applications:

  1. python manage.py startapp books
  2. python manage.py startapp contacts

Still I am only using the books application models. So I am using DATABASE_NAME like:

DATABASE_NAME = 'C:/WorkBase/Python/first/books/book.db'  

Now I want to use the second one contacts application models. How can I add contact application models to DATABASE_NAME?

My INSTALLED_APPS looks like this.

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'first.books',
    'first.contacts',  
)

Note : I am using SQLite 3 as the database.

+1  A: 

Django doesn't currently support multiple databases. However you can just syncdb your new models in your new applications and they will all go in the same database and everything will work.

Alex Gaynor
hi .Ur corret.But it can support muliple models.i want to know how to access another models (means contact application models).for that i need to change in DATABASE_NAME know..How its
Beginner
very.Thanks lazy python ,,,,,,,,,,,,,,,,
Beginner
i think trunk does :)
Dmitry Shevchenko
And Alex is the one who made that happen...
James Bennett
A: 

In SQLITE you can "Attach Database" to another SQLite database.

I am not sure of the exact syntax as I have always done this via the sqliteman "System" menu.

The attached database table uses a different "schema"/high level qualifier from the local tables but that shouldn't be a problem for Django.

James Anderson
+2  A: 

I think what Aravind is asking is "How do I create the models for my contacts app in the books.db sqlite3 database?". Most people seem to think he wants multiple db support - but that doesn't appear to be the case.

1) The name of the database file is irrelevant. Just because you called it books doesn't mean that it won't store models from all the apps in your INSTALLED_APPS.

2) To create the models for the Contacts app in the sqlite3 database you will have to do a manage.py syncdb - any new tables will be created for you, modifications of the model may require you to delete the books.db file before doing the manage.py syncdb.

Just as an example: django.contrib.auth has created tables in the books.db database file. So did any other application listed in your INSTALLED_APPS.

Hope that helps.

celopes