On Sat, May 16, 2009 at 10:03 AM, Joshua Russo <joshua.rupp...@gmail.com>wrote:

>
> 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 <joshua.rupp...@gmail.com> 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, lokeshmarema...@gmail.com wrote:
> >
> > > Hi joshua,
> >
> > > Yes, I just want to link username to details table.
> >
> > > Regards,
> > > Lokesh
> >
> > > On May 16, 7:30 pm, Joshua Russo <joshua.rupp...@gmail.com> 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, lokeshmarema...@gmail.com 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
> >
>
This is simply not true, you can have foreign keys to non primary key
fields.  As a linked the "to_field" option allows you to do just that.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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