How To Reference The Child Of A Many To One Relationship In Sqlalchemy?
Using the example off the documentation, I have the following code. When I try to append I get the error: AttributeError: 'NoneType' object has no attribute 'append' Obviously
Solution 1:
You set up the many to one relationship so that a parent can have one child and a child can have many parents. If that's how you intended, you can just set the child like so:
parent.child = child
A child, however, could add a parent like so:
child.parents.append(parent)
If this isn't how you intended, you will have to switch the relationship so that parents can have multiple children by setting up a Many to Many relationship or by switching the direction of the many to one.
Post a Comment for "How To Reference The Child Of A Many To One Relationship In Sqlalchemy?"