Wagh
Wagh

Reputation: 4306

not able to save the integer value in back-end django

I am not using django form to save data in django backend. model.py

contact_no = models.IntegerField()

views.py

number = "9739111111"
data = Profile(contact_no=number)
data.save()

on localhost its working but on server its not getting saved the contact number number is getting saved but default number is getting saved 2147483647 this number. This number is maximum range of integer.

I dont know how to save this number 9739111111 as it is. Please help me.

Upvotes: 1

Views: 1571

Answers (1)

Thomas
Thomas

Reputation: 1432

You're running into the maximum value for a 32 bit integer within a database. Try switching to a django BigIntegerField if you need to store values that large. Using your stated examples:

models.py

contact_no = models.BigIntegerField()

views.py

number = 97391111111
data = Profile( contact_no = number )
data.save()

Having said that, are you sure you're using the correct field type? If this is a phone number (as the field name suggests), do your requirements allow for you to be country specific? If so, you might want to try the localflavor app to validate and store these values appropriately.

Upvotes: 3

Related Questions