views:

27

answers:

1
+2  Q: 

django mulitidb

Hi i am using django 1.2 .I my case i have few models which are present in one db and others on second db.I have changed my settings.py file with the two database details

But when i run the server it says relation not exist.

How can i tell that for this model refer 'a' database and for others refer 'b' database.

#models.py

### this class is in a database #####


class Test(models.Model):
   id=models.AutoField(primary_key=True)
   ...
   ...
   ...
   ...
   class Meta:
      app_label=ugettext('Test')
      db_table='testing'
      verbose_name=ugettext_lazy('Testing 1,2')
   def __unicode__(self):
       return self.name


 ### this class is in b database #####


 class Test2(modes.Model):
    id=models.AutoField(primary_key=True)
    name=models.CharField(max_length=200)
    ...
    ....
    ....
    class Meta:
      app_label=ugettext('Test')
      db_table='testing2'
      verbose_name=ugettext_lazy('1,2')
    def __unicode__(self):
       return self.name

  # settings.py
   DATABASES= {  'default': {
          'NAME': 'a',
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
          'USER': 'asdf',
          'PASSWORD': '123'

         },
        'users': {
          'NAME': 'b',
      'ENGINE': 'django.db.backends.postgresql_psycopg2',
      'USER': 'asdf',
      'PASSWORD': '123'

  }
 }
+2  A: 

The django documentation has a special page for multi-db related things:

For example, a verbose way would be to specify the database to use, when a query is made, see:

For a general approach, you should specify some DATABASE_ROUTERS:

The MYYN