Hi all,

   I have 2 tables, one is A another is B, and B have one FK which contains 
more than 1 field references to A. The table struct is here:

create table A
(
  oid int not null,
  types varchar(20) not null,
  name varchar(30) null,
  color varchar(20) null,
  constraint PK_A primary key (oid,types)
)

create table B
(
 oid int not null,
 types varchar(20) not null,
......
)
alter table alter B  add constraint B_FK foreign key (oid,types) references 
A(oid,types) 



The how can i description the ModelB'f FK in Model?

class ModelA(models.Model):
    oid = models.IntegerField(max_length=10, primary_key=True)
    name = models.CharField(max_length=30,  primary_key=True)
    ....


class ModelB(models.Model):
    oid = models.ForeignKey(ModelA, to_field='oid')
    types = models.ForeignKey(ModelA, to_field='types')
    ...


However, this give errors, and not works.


Regards,
Hollandz


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0b01151a-9610-46d4-b74d-a985ee2da459%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to