Skip to content Skip to sidebar Skip to footer

Sqlalchemy Typeerror: Incompatible Collection Type: Line Is Not List-like

I have made this Schema and Insertion, I got a relationship between Line and Bar, and each Bar have a relationship also with NameBar (This is just a resume schema). My problem is t

Solution 1:

I think the error you're getting is because of the fact SQLAlchemy expects a one-to-many relationship between Bar and Line, so that one Bar has many Lines. Because of this, bar.relat would be a list of Lines, and not just a single instance.

So when you try to do newBar = Bar(zona = 'uuh', relat = newLine) SQLAlchemy expects a list of newLines for the "relat" kwarg and it complains about it.

Try and do this instead:

newBar = Bar(zona = 'uuh', relat = [newLine])

Alternatively, for cases where you do not want a one-to-many but a one-to-one relationship, you should use the uselist=False kwarg for the relationship() call, see: http://docs.sqlalchemy.org/en/latest/orm/relationship_api.html#sqlalchemy.orm.relationship.params.uselist

In this case, you can assign (and retrieve back) just a single instance and not a list.

Hope it's clear!

Post a Comment for "Sqlalchemy Typeerror: Incompatible Collection Type: Line Is Not List-like"