3

I know how to use it for CharField.

2 Answers 2

6

From the documentation:

If a field has blank=True, validation on Django’s admin site will allow entry of an empty value.

And from the null documentation:

Note that empty string values will always get stored as empty strings, not as NULL. Only use null=True for non-string fields such as integers, booleans and dates. For both types of fields, you will also need to set blank=True if you wish to permit empty values in forms, as the null parameter only affects database storage (see blank).

So blank=True basically affects only the forms. It allows to have empty form fields. But you also have to set null=True for non- string fields if you really want to allow empty values in the database as "no value" or "empty" means NULL in the database for non-string fields (for string fields, an empty value is just the empty string '' which is different from NULL).

Sign up to request clarification or add additional context in comments.

Comments

0

It means that you don't have to enter a value for the field in a form. (for example when you are using the django admin interface).

It's different from null because, blank=True might mean that when you don't enter a value, the default value (for example 0) is used, but null=True indicates that you can also store None in the field.

Look at the documentation:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.