Sometimes, we want to fix ‘You are trying to add a non-nullable field ‘new_field’ to userprofile without a default’ error with Python Django.
In this article, we’ll look at how to fix ‘You are trying to add a non-nullable field ‘new_field’ to userprofile without a default’ error with Python Django.
How to fix ‘You are trying to add a non-nullable field ‘new_field’ to userprofile without a default’ error with Python Django?
To fix ‘You are trying to add a non-nullable field ‘new_field’ to userprofile without a default’ error with Python Django, we can set a default value for the non-nullable field.
For instance, we write
new_field = models.CharField(max_length=140, default='DEFAULT VALUE')
to set the default value of new_field
to 'DEFAULT VALUE'
by calling the CharField
constructor with the default
argument.
Conclusion
To fix ‘You are trying to add a non-nullable field ‘new_field’ to userprofile without a default’ error with Python Django, we can set a default value for the non-nullable field.