我在SQLAlchemy的兩個型號,我已經自動加入一個外鍵,像這樣:指定聯接條件SQLAlchemy的ORM不用擔心外鍵
class Parent(Base):
__tablename__ = 'parents'
id = Column(Integer, primary_key=True)
name = Column(String(300), nullable=False)
metadata_id = Column(Integer, nullable=True, index=True)
class Child(Base):
__tablename__ = 'children'
id = Column(Integer, primary_key=True)
name = Column(String(300), nullable=False)
parent_metadata_id = \
Column(ForeignKey('parents.metadata_id'),
nullable=True, primary_key=True)
parent = relationship(u'Parent')
這工作得很好,我可以得到很容易從訪問父它的孩子。現在,由於技術原因超出了這個問題的範圍,我不得不擺脫我的分貝中的外鍵。我試圖在SQLAlchemy中解決這個問題,但沒有任何替換代碼(使用主要連接或backrefs)工作。我看到另一個回答here,只是說對SQLAlchemy撒謊,並告訴它我有外鍵關係,但這使得Alembic嘗試在我自動生成的每個新修訂版本上創建外鍵關係,這真的很煩人。什麼是正確的方法來做到這一點?
Downvoter,你能解釋一下你的問題與我的問題嗎? – Eli