user1328021
user1328021

Reputation: 9850

Integer out of range

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?

Upvotes: 22

Views: 35922

Answers (3)

Faddy18
Faddy18

Reputation: 11

Do not forget to migrate the changes you did, otherwise it will not work

python manage.py migrate

python manage.py makemigrations

Upvotes: 1

Merrin K
Merrin K

Reputation: 1790

Try this

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

class TableName(models.Model):
    ColumnName= models.BigIntegerField(default=0)

Upvotes: 1

Óscar López
Óscar López

Reputation: 236150

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).

Upvotes: 35

Related Questions