【发布时间】:2012-01-07 04:44:52
【问题描述】:
class PostsSubscribe(Base):
__tablename__ = 'posts_subscribe'
id = Column(Integer, primary_key = True)
post_id = Column(Integer, ForeignKey('posts_posts.id'), nullable=False)
persona_id = Column(Integer, ForeignKey('personas_personas.id'), nullable=False)
UniqueConstraint('post_id', 'persona_id') #this doesn't work.
Base.metadata.create_all(engine)
到目前为止,这是我的桌子。如您所见,我正在使用“装饰”方式来定义表格。我想创建一个唯一的密钥,但我的线路不起作用。
如何创建一个独特的配对?
【问题讨论】:
标签: mysql sql database orm sqlalchemy