On Sat, May 1, 2010 at 11:13 AM, Continuation <selforgani...@gmail.com>wrote:

>
> On Apr 30, 9:42 pm, Nick Arnett <nick.arn...@gmail.com> wrote:
>
> > If you don't have data in the table, just drop it and use
> "unique_together"
> > in models.py to define your composite key.  You'll find that in the
> Django
> > docs.  Then do syncdb and Django will create the table with your
> composite
> > key.
>
> I don't have data.
>
> Using "unique_together" wouldn't work because I want that composite
> index to be the clustered index. It'd only be the clustered index if
> it is the primary index.
>

Oh, I see now.  I often forget that Django always creates its own PK with
the id.

It should be no problem to make the Django id a unique key and the composite
key from unique_together the primary key.  I can't think of any functional
way in which they are different.  But you are right, you will have to do
this manually after syncdb.  You would still define the composite index with
unique_together, so that Django knows about it.

Just make sure you make the id column, the one that Django expects to be the
primary key, a unique index.

Although I can't think of any reason this wouldn't work, I haven't actually
tried it.  A little voice is whispering that it might affect foreign keys,
but I think they only require indexes, I don't think they have to be primary
keys.  And I think you will have to do this before you add any data, or else
the FKs will make it much harder.

Nick

>
>

-- 
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