views:

286

answers:

2

Hi all,

I'm currently building a project which involves a lot of collective intelligence. Every user visiting the web site gets created a unique profile and their data is later used to calculate best matches for themselves and other users.

By default, Django creates an INT(11) id field to handle models primary keys. I'm concerned with this being overflown very quickly (i.e. ~2.4b devices visiting the page without prior cookie set up). How can I change it to be represented as BIGINT in MySQL and long() inside Django itself?

I've found I could do the following (http://docs.djangoproject.com/en/dev/ref/models/fields/#bigintegerfield):

class MyProfile(models.Model):
    id = BigIntegerField(primary_key=True)

But is there a way to make it autoincrement, like usual id fields? Additionally, can I make it unsigned so that I get more space to fill in?

Thanks!

+2  A: 

You could alter the table afterwards. That may be a better solution.

Matthew Schinckel
A: 

I also had the same problem. Looks like there is no support for BigInteger auto fields in django.

I've tried to create some custom field BigIntegerAutoField but I faced a problem with south migration system (south couldn't create sequence for my field).

After giving a try couple of different approaches I decided to follow Matthew's advice and do alter table (e.g. ALTER TABLE table_name ALTER COLUMN id TYPE bigint; in postgre)

Would be great to have solution supported by django (like built in BigIntegerAutoField) and south.

Lukasz Dziedzia
I think this wouldn't help, as Django would still put id's into normal int, which is still too small.
Alex Letoosh
Not at all, the point here is how id is stored on database. (Long) integer type in python has 'unlimited' precision. You can also check how BigIntegerField is implmented in Django 1.2 - it inherits directly IntegreField, without changing internal type to store the value (which is int in this case)
Lukasz Dziedzia
You're right, my bad...
Alex Letoosh