Can I make the foreign key field optional in Django model

后端 未结 1 1328
[愿得一人]
[愿得一人] 2020-12-04 10:52

I have this code

subject      = models.ForeignKey(subjects)
location     = models.ForeignKey(location)
publisher    =  models.ForeignKey(publisher)


        
相关标签:
1条回答
  • 2020-12-04 11:02

    Sure, just add blank=True, null=True for each field that you want to remain optional like

    subject = models.ForeignKey(subjects, blank=True, null=True)
    
    0 讨论(0)
提交回复
热议问题