On Wed, Apr 28, 2010 at 8:09 PM, Continuation <selforgani...@gmail.com>wrote:

> I'm using MySQL with Django.
>
> MySQL uses clustered index. I have a class AuctionBid for which the
> "natural" PK is (user_id, auction_id).
>
> I'd like to set (user_id, aucton_id) as the PK so that it'll be the
> clustered index. I understand that Django doesn't support composite
> PK. But what if after syncdb I just ALTER TABLE to make (user_id,
> aucton_id) the PK. Would that work with Django or would that introduce
> some unwanted behavior under the hood?


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.

Otherwise, you can make the change in models.py, as above, and change the PK
manually.

If there are FKs involved, you might also want to make the appropriate
changes if you're not re-creating all the involved tables with syncdb.

One other route, if you have data, is to rename the existing tables (can be
tricky with FKs), then syncdb and then copy your data... or, even easier,
create a whole new database with syncdb and copy your data into it.

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