Differences between null and blank in Django Models

Source: Internet
Author: User
Blank stores an empty string in the database.

To set a field, enter blank = true. The default value is blank = false (required );

Null represents null in the database, rather than an empty string.

If you need to set the field to NULL: null = true, the default value is null = false (the field must be filled in );

Note:

The date type (datefield, timefield, datetimefield) and numeric type (integerfield, decimalfield, floatfield) cannot accept null strings. Therefore, if you want to set the fields of the two types to be null, you must set both null = true and blank = true;

Summary (the summary is from the blog site ccorz)

Null is used for databases. If null = true, this field of the database can be null.
Blank is for a form. If blank is set to true, this field can be left blank when your form is filled in. For example, when you add a model record to the admin interface. This field is not in bold.



Zero _ WYF
Link: https://www.jianshu.com/p/108697dfb899
Source: Simplified book
The copyright of the simplified book belongs to the author. For any form of reproduction, please contact the author for authorization and indicate the source.

Differences between null and blank in Django Models

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.