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
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