📜  在 django mdoels 中使用默认为 none - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:28.480000             🧑  作者: Mango

代码示例1
>>> type('')

>>> type(None)

>>>

Avoid using null on string-based fields such as CharField and TextField. 
If a string-based field has null=True, that means it has two possible values for “no data”: NULL, and the empty string. 
In most cases, it’s redundant to have two possible values for “no data;” 
the Django convention is to use the empty string, not NULL.
One exception is when a CharField has both unique=True and blank=True set. 
In this situation, null=True is required to avoid unique constraint violations when saving multiple objects with blank values.