views:

48

answers:

1

hi,

if you have millions of entries in a mysql table, you often want to manipulate it with a hexadecimal primary key (in practice you do a md5(name)). The queries are then much faster.

Is there a way to do this with Django? If not, the usual int primary key isn't limitating? How to specify that you want a big integer?

A: 

You can use whatever you like as the primary key in Django. Just add primary_key=True to the model arguments. E.g.

foo = models.CharField(max_length=36, primary_key=True)

Here are the Django docs on this topic.

Hope this helps.

godswearhats
and you can only have one primary key per class?
Mermoz
You can only have one primary key per _table_. That's a database thing, not a Django thing. However, the database generally allows you to make a primary key of multiple columns. I'm not sure what the behaviour would be if you specified two primary keys in your model. Why not try it out and see? :-)
godswearhats