Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I have a problem with Django database. in model

I have specified that my bio and image fields can be empty, but why does it give me an error and say that I have to fill it in?enter image description here

class User_account(models.Model):
    email = models.EmailField()
    fullname = models.CharField(max_length=30)
    username = models.CharField(max_length=20)
    password = models.CharField(max_length=30)
    marital_status = models.BooleanField(default=False)
    bio = models.CharField(null=True, max_length=200)
    visitor = models.IntegerField(default=0)
    image = models.ImageField(null=True, upload_to='profile_img')

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Specifying null=True [Django-doc] does not mean the field is not required. null=True has only impact on the database: it makes the field NULLable. You should use blank=True [Django-doc] to make the field not required:

class User_account(models.Model):
    # …
    bio = models.CharField(null=True, blank=True, max_length=200)
    # …
    image = models.ImageField(null=True, blank=True, 

Note: Models in Django are written in PascalCase, not snake_case,
so you might want to rename the model from User_account to UserAccount.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading