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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -