I have this architecture (very simplified)
from django.db import Models
class MainClass(models.Model):
a = models.IntegerField()
b = models.CharField()
class OtherClass(models.Model):
c = models.IntegerField()
main = models.OneToOneField(MainClass, primary_key=True)
Which means my MainClass object has an attribute named otherclass, because of the existence of the reverse relationship between these models.
My problem is if I specify valid values for MainClass.a and MainClass.b, but None for MainClass.otherclass. I get the error
ValueError: Cannot assign None: "MainClass.otherclass" does not allow null values.
I understand there cannot be OtherClass without MainClass (it doesn't make sense), but why the opposite situation is also causing an error? Other way: Why cannot be MainClass without OtherClass?
答案 0 :(得分:0)