I've seen all the similar threads, read the docs, and tried many combinations to store an empty value as IntegerField
in db and failed every single time.
I am using MySQL.
My models.py
defines an age=models.IntegerField()
field. I populate db from csv file, and some cells have no value. Django docs says:
Field.null
If True, Django will store empty values as NULL in the database. Default is False.
Note that empty string values will always get stored as empty strings, not as NULL.
Since I am working with IntegerField
I want an empty string (an empty cell from the csv) to be stored as NULL
in db. Therefore, I (think) have to add null=True
to the age
field. Actually, I've tried more than this:
age=models.IntegerField()
age=models.IntegerField(null=True)
age=models.IntegerField(null=True, blank=True)
age=models.IntegerField(null=True, blank=True, default=None)
and every time I am inserting an empty string to a db I got
ValueError: invalid literal for int() with base 10: ''
Any guess what else can I do?