I don't think there is a "right(tm)" way, but there are some things to
consider.  A lot of people would argue that a unique characteristic makes a
very good primary key, I think I might be one of them.  But, remember that
data reflects the real world.  In general, a person's name isn't very
unique.  So if you really have some data that has a real unique
characteristic, then use it as the primary key.  If you are really setting
up a Person table, don't use the name as a primary key.  You probably will
be altering the table sooner rather than later to remove the unique
designation.  The last department I worked in had 3 Mike's in about a dozen
people.  That is why governments invent things like SSN, to make you
unique.  So in that case, an implicit id is going to work better, but know
you have to figure out how to keep the 3 John Smiths apart.

On 4/25/07, Kai Kuehne <[EMAIL PROTECTED]> wrote:
>
>
> Hello list,
> I have a question regarding general database design.
> Ok.. which method would you recommend, if you have a table
> with a field 'name' which values should be unique in the whole table?
>
> 1) use (implicit) id which is automatically added by django, as primary
> key and a 'name' field with "unique=True" set:
>
> class Person(models.Model):
>     name = models.CharField(maxlength=255, unique=True)
>
>
> 2) or the name directly as the primary key of the table without an id:
>
> class Person(models.Model):
>     name = models.CharField(maxlength, primary_key)
>
> I'm a bit confused on how do it 'right(tm)'. Is there a
> rule or how would you do it?
>
> Thanks for ideas
> Kai
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to