How to set NULL for IntegerField instead of setting 0?

后端 未结 1 1443
天涯浪人
天涯浪人 2021-02-12 11:18

I\'m uploading some data from an excel file using xlrd and turning that data into models (with mainly IntegerField values) in Django. My excel file has a bunch of missing data.

1条回答
  •  南方客
    南方客 (楼主)
    2021-02-12 11:49

    Instead of using

    age = models.IntegerField()
    

    use

    age = models.IntegerField(blank=True, null=True)
    

    When we specify

    blank=True, null=True
    

    it will allow you to store null in that column

    0 讨论(0)
提交回复
热议问题