Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer out of range

Tags:

python

django

I'm getting an integer out of range error when trying to migrate my database from SQLite to PostgreSQL.

I think I have pinpointed the problem: I have some huge integers in a IntegerField field in my model.

Basically on the order of 52675215334.

When I change this value to a small number like 1 and then try to migrate my database, all is fine.

Is there some other data type I should be using other than IntegerField to store these large values?

like image 221
user1328021 Avatar asked Jul 02 '12 23:07

user1328021


People also ask

What is integer out of range?

NumericValueOutOfRange: integer out of range. The error means that in the table the column in which the data was tried to be saved is out of the acceptable range of the number.

What is Bigint in PostgreSQL?

PostgreSQL BIGINT is numeric data type used in PostgreSQL to store integer type of values, we can store the integer type of value using bigint data type in PostgreSQL. The size of bigint data type in PostgreSQL is 8 bytes and range of bigint data type is -9223372036854775808 to 9223372036854775807.

How do I write a cast in PostgreSQL?

PostgreSQL supports a CAST operator that is used to convert a value of one type to another. Syntax: CAST ( expression AS target_type ); Let's analyze the above syntax: First, specify an expression that can be a constant, a table column, an expression that evaluates to a value.


2 Answers

Try using BigIntegerField if you integers are that big. From the documentation:

A 64 bit integer, much like an IntegerField except that it is guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807. The admin represents this as an <input type="text"> (a single-line input).

like image 178
Óscar López Avatar answered Sep 24 '22 06:09

Óscar López


Try this

Change models.IntegerField() to models.BigIntegerField()

class TableName(models.Model):
    ColumnName= models.BigIntegerField(default=0)
like image 22
Merrin K Avatar answered Sep 23 '22 06:09

Merrin K