database design - Django model relations how to make it optional -


models.py:

class time(models.model):     id = models.autofield(primary_key=true)     who=  models.textfield(db_column='who')  class task(models.model):     id = models.autofield(primary_key=true)     when=  models.foreignkey(time) 

i need record time , task problem there can be:

1) time without task,

2) task without time,

3) time multiple task

i've tried adding foreignkey task null , blank = true django says "foreignkey can't null"

are there other way make "optional" relation?

when =  models.foreignkey(time, default=none, blank=true, null=true) 

and make new migration change schema:

python manage.py makemigrations  python manage.py migrate 

you getting

foreignkey can't null 

because schema doesnot allow fk null


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -