Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Base = declarative_base()
- class User(Base):
- __tablename__ = 'users1'
- id = Column(Integer, primary_key=True)
- name = Column(String)
- fullname = Column(String)
- password = Column(String)
- def __repr__(self):
- return "<User(name='%s, username = '%s', password='%s')>" %(self.name, self.fullname, self.password)
- engine = create_engine('sqlite:///test2.db', echo=True)
- Base.metadata.create_all(engine)
- Session = sessionmaker(bind=engine)
- Session = sessionmaker()
- Session.configure(bind=engine)
- session = Session()
- class Address(Base):
- __tablename__ = 'addresses'
- id = Column(Integer, primary_key=True)
- email_address = Column(String, nullable=False)
- user_id = Column(Integer, ForeignKey('users.id'))
- user = relationship("User", back_populates="addresses")
- def __repr__(self):
- return "<Address(email_address='%s')>" % self.email_address
- User.addresses = relationship("Address", order_by=Address.id, back_populates="user")
- sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship User.addresses - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement