python - I cannot solve Django models.DateField ValidationError -


i stuck error models.datefield()

first, did this.

models.py

from datetime import date, datetime django.db import models  class user(models.model):     uid = models.autofield(primary_key=true)     birthdate = models.datefield() 

then, got,

$ python manage.py makemigrations trying add non-nullable field 'birthdate' user_profile without default; can't (the database needs populate existing rows). please select fix:  1) provide one-off default (will set on existing rows)  2) quit, , let me add default in models.py 

so, did,

models.py

from datetime import date, datetime 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, "'' invalid formate of date. should change yyyy-mm-dd".

how should change code? thank you.

/// additional /// if can, don't want insert date birthdate field. seems have to. can let blank?

birthdate = models.datefield(null=true, blank=false) 

didn't work.

python 3.5.1 django 1.9.1

sounds migration files messed up. when migration, django create migration file records did. in short, changed model code many times, never changed migration file, or creating duplicate migration files.

the following should want,

birthdate = models.datefield(null=true, blank=true) 

but noticed, cleaning migration files related change , create new 1 should solve problem.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -