how to create bigint ?

140 views
Skip to first unread message

xankya

unread,
Mar 12, 2009, 2:26:35 PM3/12/09
to Django users
I created an integer field for a mobile number as
mobile = models.IntegerField(max_length=20)

In MySQL interface, it created an integer field with length 11.

So my question is how to create bigint in mysql for storing big
numbers such as mobile number.

And my another mysql newbie question is why int(length=20) in mysql
can't store 10 digit number? and is bigint(length=5) different that int
(length=5)?

Karen Tracey

unread,
Mar 12, 2009, 8:49:10 PM3/12/09
to django...@googlegroups.com
On Thu, Mar 12, 2009 at 2:26 PM, xankya <suzan....@gmail.com> wrote:

I created an integer field for a mobile number as
mobile = models.IntegerField(max_length=20)

In MySQL interface, it created an integer field with length 11.

So my question is how to create bigint in mysql for storing big
numbers such as mobile number.

And my another mysql newbie question is why int(length=20) in mysql
can't store 10 digit number?

Specifying max_length on a Django model IntegerField has no effect.  max_length is an allowed parameter on any field, but it is not used except by those fields (such as CharField) that are documented to use the value.
 
and is bigint(length=5) different that int
(length=5)?

I'm not sure what you are asking here?  Django doesn' t have a big integer field.  Your choices (unless you want to use a custom field) are Integer and SmallInteger, which map (on MySQL) to integer and smallint respectively.  There is an old ticket (#399) requesting a BigInt field, but it has not been completed.  (Since it was opened it has become much more easy to write your own custom fields so adding this ticket to core became not as important as originally.)

Anyway, I'm not sure why you need to store a phone number as an integer?  A CharField with (formfield-level, at the moment) validation to ensure it's got the right number of digits or whatever would seem to work fine.

Karen

Kegan Gan

unread,
Mar 12, 2009, 11:37:13 PM3/12/09
to Django users
I was just facing this 'requirement' a couple of days ago. I needed an
Integer field that stores up to a hundred billion. Django's
IntegerField get mapped as 32 bit field in PostgreSql, and just can
represent integer over 2++ billion. (It worked on my development
environment using sqlite though).

My solution is just to ALTER table manually after syncdb. I believe
you can easily automated that using signal on post-syncdb.

jai

unread,
Mar 13, 2009, 2:27:15 AM3/13/09
to Django users
i used to store mobile/phone number as follows
phone=models.DecimalField(max_digits=10, decimal_places=0)
so that u can store up to 10 digit or else if u want to store 12 digit
number then give max_digits=12.
Hope this will fix your problem.

xankya

unread,
Mar 13, 2009, 2:35:36 AM3/13/09
to Django users
Thanks Karen Tracey and Kegan Gan. I'll check the issues of storing
large numbers later, and will post the results.


> and is bigint(length=5) different that int
> (length=5)?

by this i meant to ask, creating bigint of length 5 (say) in mysql
does make sense? in other words, for length 5, we would normally
create int field of length 5 in mysql. so my question is creating
bigint of length 5 does have any overhead or it is no different that
int field of length 5.

Ozan Onay

unread,
Mar 13, 2009, 8:43:10 AM3/13/09
to Django users
As Karen pointed out, you should consider a phone number to be a
string, not an integer. Integers are there to do mathematical
operations on, which I can't imagine you requiring for a phone number
(what's the relevance of my phone no. + 5?). Also anything that you
would want to do with a phone number would be attained more naturally
through string methods. Say you wanted to retrieve the last 4 digits -
using phone_str[-4:] makes more sense than phone_int % 10000.

Don't be fooled by the fact that that phone numbers have numerals in
them - phone "numbers" could well have used alphabetical characters,
or colors, or anything else that could map to a series of frequencies.

Jeff FW

unread,
Mar 13, 2009, 12:40:56 PM3/13/09
to Django users
Especially since international phone numbers can start with 0--try
storing that in an integer field, and you'll immediately run into
problems.
Reply all
Reply to author
Forward
0 new messages