Why are blank and null distinct options for a django model?

前端 未结 2 640
闹比i
闹比i 2020-12-28 09:44

When defining fields in a django model, there are two ways to say that the field is allowed to be empty. null means it can be empty in the database, and

2条回答
  •  心在旅途
    2020-12-28 10:18

    null=False, blank=True is common for CharFields, where a blank answer is stored in the db as a blank string rather than a null. The other way around doesn't make much sense to use.

    For non-string fields, a non-answer is stored as a null, and so you need both.

提交回复
热议问题