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 - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -