tags:

views:

2012

answers:

3

In short: How do you specify a BIGINT in Django models?

In a current project I am doing using Django (0.97-svn release), I've all the integer fields in all the models defined as IntegerField. It was working immaculately during the development cycle where I was using SQLite for the DB backend. However, as soon as I rolled off to MySQL, I noticed that for one of the IntegerFields, MySQL was truncating data---apparently, for reasons still unknown to me, SQLite didn't complain. I looked at the schema and found out that an IntegerField in Django is represented as an INT(11) field in MySQL. Naturally, the reason MySQL was truncating data was because the data was more than 11-digit in length. To workaround, I had to manually update the column to, in this case, be a BIGINT(20). Django and MySQL coexist peacefully with that. But whenever I reset the application in which rests the model containing that BIGINT, Django again creates it as an INT(11). I've looked at Django docs, and not found anything. Have I overlooked something?

Thanks.

+3  A: 

SQLite won't complain ever. it uses 'manifest typing', that is, the values have type, not the columns. It lets you store bigtext on a smallint collumn, or whatever you want! (except if you define an integer primary key, where it uses a 64-bit integer).

that's a very convenient feature, but it makes a SQLite bad choice for developing if you're going to deploy with a different engine.

for using a BIGINT, you'd have to create a custom field class. unfortunately, that part has changed on Django 1.0, so you'd have to rewrite it if/when you update.

Javier
+1  A: 

Try a DecimalField.

+2  A: 

BigIntegerField was added in changeset 11887, 2009-12-17 09:10:38 and is part of Django 1.2 and newer.

kaleissin
+1 for solving my issue.
bennedich