Python之SQLAlchemy学习--外键约束问题

以下问题赞为解决:

# class User(Base):
# __tablename__ = 'user'
# #表的结构
# id = Column(String(20), primary_key=True)
# username = Column(String(20))
# books = relationship('Book')
# class Book(Base):
# __tablename__ = 'book'
#
# id = Column(String(20), primary_key=True)
# name = Column(String(20))
# # “多”的一方的book表是通过外键关联到user表的:
# user_id = Column(String(20), ForeignKey('user.id'))
posted @ 2015-12-09 12:00  半天的半天  阅读(798)  评论(0编辑  收藏  举报