There are the following models:

class SwitchEquipment (models.Model): class Meta(): db_table = 'switch_equipment' switchequipment_networkname = models.TextField() switchequipment_network = models.ForeignKey(Network) class Network(models.Model): class Meta(): db_table = 'network' network_name = models.TextField() network_switch = models.ManyToManyField(SwitchEquipment) 

According to my idea, the network_switch and switchequipmet_network fields I want to make optional. Tried to add blank = True, but did not help. Tell me, is it possible my idea in Django?

  • one
    You have not studied the link that I gave you earlier. For one model, you specify the many-to-one interaction, the second for the many-to-many. Do you think this is normal? - Nikmoon
  • Look here for a very similar question - Nikmoon

1 answer 1

For m2m field is enough to add blank=True , this will make the field optional during validation.
For ForeignKey , you need to add blank=True for the same purpose and null=True so that you can store null in the database.