[Django]-Django throwing "invalid literal for int() with base 10: ''" when trying to save object attribute

8👍

The problem ended up being that I was not passing a value for the integer field last_4_digits. It seems that this happens if you have a integerField with blank=True and don’t submit a value for it.

3👍

I experienced this error message as well in a Django population script with a ForeignKey having both blank=True and null=True, and passing ''
as argument to objects.get_or_create().

I fixed the issue by passing argument=None. The None part is the clue.

👤SaeX

0👍

This type of error is occur when an “Integer” inupt contains empty or string value like ” ‘id’ “, ” ‘.’.”, etc.
So, you have to find out that for what this type of input you get.

0👍

The problem for me was that I was using required=False, disabled=True, that didn’t send the data to the server for that field. I changed to

amount_payments = CharField(widget=TextInput(attrs={'readonly': 'readonly'}))

Leave a comment