I am stuck with an Error with models.DateField()
First, I did this.
models.py
from datetime import date, datetime
from django.db import models
class User(models.Model):
uid = models.AutoField(primary_key=True)
birthdate = models.DateField()
Then, I got,
$ python manage.py makemigrations
You are trying to add a non-nullable field 'birthdate' to user_profile without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
So, I did,
models.py
from datetime import date, datetime
from django.db import models
class User(models.Model):
uid = models.AutoField(primary_key=True)
birthdate = models.DateField(default=date.today)
Then,
$ python manage.py migrate
django.core.exceptions.ValidationError: ["'' は無効な日付形式です。YYYY-MM-DD形式にしなければなりません。"]
The error means, like "'' is invalid for formate of date. You should change to YYYY-MM-DD".
How should I change this code? Thank you.
/// additional /// If I can, I don't want to INSERT date INTO birthdate field. But it seems I have to. Can I let it blank?
birthdate = models.DateField(null=True, blank=False)
didn't work.
Python 3.5.1 Django 1.9.1