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?
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.
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.
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.
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).
Try this
Change models.IntegerField() to models.BigIntegerField()
class TableName(models.Model):
ColumnName= models.BigIntegerField(default=0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With