secondary argument %s passed to to relationship() %s must be a Table object or other FROM clause; can't send a mapped class directly as rows in 'secondary' are persisted independently of a class that is mapped to that same table.
Package:
sqlalchemy
4189
Exception Class:
sa_exc.ArgumentError
Raise code
coercions.expect(
roles.ColumnArgumentRole, val, argname=attr
)
),
)
if self.secondary is not None and _is_mapped_class(self.secondary):
raise sa_exc.ArgumentError(
"secondary argument %s passed to to relationship() %s must "
"be a Table object or other FROM clause; can't send a mapped "
"class directly as rows in 'secondary' are persisted "
"independently of a class that is mapped "
"to that same table." % (self.secondary, self)
)
# en
🙏 Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/sqlalchemy/sqlalchemy/blob/6dbcb792eb60d4e084f0d1252882a0cbad4bc673/lib/sqlalchemy/orm/relationships.py#L2203Ways to fix
When I ran into this issue all I had to do was replace
class AuthorBook (Base):
__tablename__ = 'author_book',
id = Column(Integer, primary_key = True)
author = Column(ForeignKey('authors.id'))
book = Column(ForeignKey('books.id'))
with
AuthorBook = Table(
'author_book',
Base.metadata,
Column('id', Integer, primary_key = True),
Column('author', ForeignKey('authors.id')),
Column('book', ForeignKey('books.id'))
)
just like the error says
secondary argument %s passed to to relationship() %s must be a **Table** object ...
Add a possible fix
Please authorize to post fix