In Django models.py, what's the difference between default, null, and blank?

前端 未结 5 1258
-上瘾入骨i
-上瘾入骨i 2020-12-04 12:45
  • null=True
  • blank=True
  • default = 0

What\'s the difference? When do you use what?

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 13:38

    I know you already have your answer however till this day it's difficult to judge whether to put null=True or blank=True or both to a field. I personally think it's pretty useless and confusing to provide so many options to developers. Let the handle the nulls or blanks however they want.

    I follow this table (from the book "Two Scoops of Django"):

提交回复
热议问题