[Django]-Out of range value adjusted for column warning in django when adding a large integer (11 chars)

4👍

You should create custom field inhrited from Field or IntegerField

class BigintField(models.Field):
    def db_type(self):
        return 'BIGINT(20)'
...

and

class MyModel(models.Model):
    bigid = BigintField()
👤N. Aff

3👍

For modern Django versions, use the models.BigIntegerField. It supports larger values.

👤vdboor

2👍

Django ticket #399 deals with this. I also opened a similar question quite some time ago.

A workaround that I have used in the past is to simply ALTER the field in question directly in the DB table to BIGINT (for MySQL, for example). Note, however, that if you reset the application in which the particular model with the particular field exists, or drop the table and recreate it by any means, you will have to ALTER the field again.

👤ayaz

0👍

For South users, django’s built-in DecimalField may work better than the custom BigintField approach above. Looks like it takes a bit of extra work to teach South about custom field types.

Leave a comment