Hi All, still trying to get my head around the multi db stuff in 1.2
release.

Here is my problem that I have hit upon.

I have a model in my default db...

class Set1(models.Model):
    create_date = models.DateTimeField(auto_now_add='True')
    last_update = models.DateTimeField(auto_now='True', null=True)
    fields = models.ManyToManyField(Field)
    project = models.ForeignKey(Project)

This model has a m2m relationship to Field. This Field table (called
HASH_TABLE) is an existing table on another database so in models I
have...

class Field(models.Model):
    NAME = models.CharField(max_length=10,primary_key=True)
    HASHCODE = models.DecimalField(decimal_places=0,max_digits=64)

    class Meta:
        managed = False
        db_table = 'HASH_TABLE'

In a script to populate the database I have...

for row in upload:
        field = Field.objects.using('apcc').get(NAME=row[1])
        project = Project.objects.get(pk=row[2])
        set1 = Set1(project=project)
        set1.save()
        set1.field.add(field) # add m2m relationship

running the script I get the error...

Cannot add "<Field: test>": instance is on database "default", value
is is on database "test_database"

I currently have the m2m table (linking Set1 to Field) on the default
database (which is where I'd like to keep it) but how do I get around
this problem? Does anyone have an example of multi db use where you
have a m2m relationship between tables on different datbases?

Many thanks,

Martin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to