したがって、SQLAlchemy(0.8)ではこの1対多の関係があります。
class Parent(Base):
__tablename__ = "parents"
cid = Column(Integer(11), primary_key = True, autoincrement = False)
uid = Column(Integer(11), ForeignKey('otherTable.uid',
ondelete = 'CASCADE'), primary_key = True)
...
# Relationship with child
childs_rel = relationship("Child", backref = 'parents',
cascade = "all, delete-orphan")
と
class Child(Base):
__tablename__ = "childs"
mid = Column(Integer(11), primary_key = True, autoincrement = False)
cid = Column(Integer(11), ForeignKey('parents.cid',
ondelete = 'CASCADE'), primary_key = True)
uid = Column(Integer(11), ForeignKey('parents.uid',
ondelete = 'CASCADE'), primary_key = True)
...
このデータベースを作成することはできますが、それを操作しようとすると、次のエラーが発生します。
sqlalchemy.exc.AmbiguousForeignKeysError:関係Parent.childs_relの親/子テーブル間の結合条件を判別できませんでした-テーブルをリンクする複数の外部キーパスがあります。'foreign_keys'引数を指定して、親テーブルへの外部キー参照を含むものとしてカウントする必要がある列のリストを提供します。
childs_relで「foreign_keys」を指定しようとしましたが、Parentのクラスに外部キーがないと言われています。これは本当です...これは子のクラスで指定する必要がありますが、SQLAlchemyのORMドキュメントによると、関係は「 「1対多」の関係の1つ..
http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#one-to-many
ここで何が起こっていると思いますか?ありがとう!