1
親愛的大家,我下面就http://www.sqlalchemy.org/docs/mappers.html#many-to-many的SQLAlchemy:多對多的關係錯誤
#This is actually a VIEW
tb_mapping_uGroups_uProducts = Table('mapping_uGroups_uProducts', metadata,
Column('upID', Integer, ForeignKey('uProductsInfo.upID')),
Column('ugID', Integer, ForeignKey('uGroupsInfo.ugID'))
)
tb_uProducts = Table('uProductsInfo', metadata,
Column('upID', Integer, primary_key=True)
)
mapper(UnifiedProduct, tb_uProducts)
tb_uGroupsInfo = Table('uGroupsInfo', metadata,
Column('ugID', Integer, primary_key=True)
)
mapper(UnifiedGroup, tb_uGroupsInfo, properties={
'unifiedProducts': relation(UnifiedProduct, secondary=tb_mapping_uGroups_uProducts, backref="unifiedGroups")
})
其中uProduct和uGroup之間的關係是N描述的多對多的關係:M。
當我運行以下
sess.query(UnifiedProduct).join(UnifiedGroup).distinct()[:10]
我收到錯誤:
sqlalchemy.exc.ArgumentError: Can't find any foreign key relationships between 'uProductsInfo' and 'uGroupsInfo'
我在做什麼錯?
編輯:我是上的MyISAM不支持forigen鍵