votes up 1

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:
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
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 1 votes down

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

Jul 10, 2022 Adophilus answer

Add a possible fix

Please authorize to post fix