Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. Base = declarative_base()
  2. class User(Base):
  3. __tablename__ = 'users1'
  4.  
  5. id = Column(Integer, primary_key=True)
  6. name = Column(String)
  7. fullname = Column(String)
  8. password = Column(String)
  9.  
  10. def __repr__(self):
  11. return "<User(name='%s, username = '%s', password='%s')>" %(self.name, self.fullname, self.password)
  12.  
  13.  
  14.  
  15. engine = create_engine('sqlite:///test2.db', echo=True)
  16. Base.metadata.create_all(engine)
  17.  
  18. Session = sessionmaker(bind=engine)
  19. Session = sessionmaker()
  20. Session.configure(bind=engine)
  21. session = Session()
  22.  
  23. class Address(Base):
  24. __tablename__ = 'addresses'
  25. id = Column(Integer, primary_key=True)
  26. email_address = Column(String, nullable=False)
  27. user_id = Column(Integer, ForeignKey('users.id'))
  28. user = relationship("User", back_populates="addresses")
  29. def __repr__(self):
  30. return "<Address(email_address='%s')>" % self.email_address
  31.  
  32. User.addresses = relationship("Address", order_by=Address.id, back_populates="user")
  33.  
  34. 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