0
我的表是這樣的:映射針對可選擇和獲得正確的主鍵中的SQLAlchemy
from sqlalchemy import Column, Integer, select
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Blah(Base):
__tablename__ = 'Blah'
container_id = Column(Integer, primary_key=True)
blah_id = Column(Integer, primary_key=True)
gprop = Column(Integer, index=True, nullable=False)
class GProp(Base):
__table__ = select([
Blah.container_id, Blah.gprop
]).group_by(
Blah.container_id, Blah.gprop
).alias()
因爲它是GProp.__table__.primary_key
拾起container_id
列,但我不能找到一種方法,使gprop
主鍵的列部分。這打破了我的查詢,SQLAlchemy將只爲每個容器加載一個GProp
。
失敗修復至今:添加Column
屬性是被禁止的,因爲它重新定義現有列,增加一個PrimaryKeyConstraint
到__table_args__
沒有效果,和猴子修補__table__.primary_key
得到由剛剛錯斷言抓獲。