I'm struggling with how I can set a NOT NULL constraint on a charfield.
Currently, my model looks like this:
class Tutors(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20, blank=False)
email = models.EmailField(max_length=254)
birth_day = models.DateField(auto_now=False, auto_now_add=False)
def __str__(self):
return(self.first_name + ' ' + self.last_name)
I want to make sure that last_name and first_name can't be saved to the database as NOT NULL. Docs are confusing me a bit lol
If you don't specify null in your model class. null=False is default
Django Documentation
blank=False will enforce that any form for this model cannot have a blank value for that field. To set NOT NULL on the underlying database column, also include null=False.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With