I should probably explain that better. Inside the DB foreign keys can
only be made between a field in a child/related table to a primary key
field. Generally the primary key fields don't change as often, though
you can change them just like any other field it's highly
unrecommended.

If you try to change a primary key value that already has other
records pointing to it via foreign keys you will generally get an
error. There are ways to setup the DB to cascade updates made to
primary keys to the foreign keys but the functionality is not
universal to all types of DBs and has it's own limitations.

Does this make sense?


On May 16, 1:52 pm, Joshua Russo <[email protected]> wrote:
> You want to link to the id field in the auth_user table. Try the
> following:
>
> from django.contrib.auth.models import User
>
> class details(models.Model):
>     user = models.ForeignKey(User)
>
> On May 16, 1:38 pm, [email protected] wrote:
>
> > Hi joshua,
>
> > Yes, I just want to link username to details table.
>
> > Regards,
> > Lokesh
>
> > On May 16, 7:30 pm, Joshua Russo <[email protected]> wrote:
>
> > > Foreign keys only point to primary key values. That's just how
> > > relational DBs work
>
> > > It looks like you just want to link details to a user. Is that
> > > correct?
>
> > > On May 16, 12:46 pm, [email protected] wrote:
>
> > > > Hi All,
>
> > > > Is it possible to create a foreign key to a model referring to a non
> > > > primary column from other model.
>
> > > > class details(models.Model):
> > > >     username = ????????
>
> > > > ?????? -> how I can refer this field as a foreign key to username
> > > > column which is from auth_user table.
>
> > > > Thanks in advance.
>
> > > > Regards,
> > > > Lokesh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to