Hi, I can’t figure out how to link to someone else’s key using sqlalchemy. I created a new table client in my database:
class Client(DeclarativeBase): __tablename__ = 'client' id = Column(Integer, primary_key=True) user_id = Column( Integer, ForeignKey('user.id', ondelete='CASCADE'), nullable=False, index=True, ) orgname = Column(Unicode, nullable=False) def __init__(self, **kwargs): super(Client, self).__init__(**kwargs)
Not trying to do something like this
u = User(user_name=u'dusual') session.add(u) c = Client(user=u, orgname="dummy_org") session.add(c)
But sqlalchemy yells back saying:
(k, cls _. name )) TypeError: "user" is an invalid keyword argument for the client
Now it should not be obvious that the user should be allowed as a keyword argument, how can I make sure that my table can accept a user keyword argument.
dusual
source share