Reputation:
IntegrityError: NOT NULL constraint failed: app_userprofile.email
The field looks like this:
email = models.CharField(max_length=100, blank=True, default=None)
I do not understand. Error happens when creating instance of the model and not setting the email field. But it's blank and it's charfield, and None if not overwritten, why is it happening?
Upvotes: 4
Views: 4303
Reputation: 3371
There are two option:
null = True
which is used if you want to save null value in Database.blank = True
which is used for form validation. You can call save form without value in that field.In your current issue you just have to add null = True
.
email = models.CharField(max_length=100, blank=True, null=True, default=None)
Upvotes: 2
Reputation: 2208
As noted here, using null=True in charField and TextField should be avoided. Because then your field has two options for no data. one is None another is blank string.
By the way null is by default set to False in django fields and you should set it to True in your case.
Upvotes: 1