[Django]-I cannot solve Django models.DateField ValidationError

2👍

Sounds like your migration files are messed up. When you do a migration, django would create a migration file that records what you did. So in short, you changed your model code many times, but you never changed your migration file, or you are creating duplicate migration files.

The following should be what you want,

birthdate = models.DateField(null=True, blank=True)

But as you noticed, cleaning up all migration files that related to this change and create a new one should solve the problem.

1👍

What you have tried should work:

birthdate = models.DateField(null=True, blank=False)

This allows the database to accept null values (which it does during the migration) and blank means that django will not accept empty values from forms.

Make sure to delete migrations that have been made but not applied. Also try deleting all .pyc’s in your project.

1👍

Try this,

birthdate = models.DateField(null=True, blank=False)

Leave a comment