Мои связи в таблице в SQLAlchemy получили довольно сложную задачу, и теперь я застреваю в этой ошибке независимо от того, как я настраиваю свои отношения.SQLAlchemy InvalidRequestError при использовании составных внешних ключей
Я немного новичок в SQLAlchemy, поэтому я не уверен, что я делаю неправильно, но я продолжаю получать ту же ошибку, независимо от того, что я делаю.
У меня есть иерархия таблиц, все наследуются от «Узла», которая представляет собой таблицу с самореференциальными идентификаторами и родительскими столбцами. Все это работает. Теперь у меня есть другая таблица «Информация», содержащая составной первичный ключ, на который ссылается другая таблица узлов «Виджет».
Base = declarative_base()
class Node(Base):
__tablename__ = 'Node'
id = Column(Integer, primary_key=True)
parentid = Column(Integer, ForeignKey('Node.ID')
type = Column(Text(50))
children = relationship('Node')
__mapper_args__ = {
'polymorphic_identity': 'Node',
'polymorphic_on': type
}
class Information(Node):
__tablename__ = 'Information'
id = Column(Integer, ForeignKey('Node.ID'), primary_key=True)
Name = Column(Text, primary_key=True)
Number = Column(Float, primary_key=True)
Widgets = relationship('Widget', backref='ThisInformation')
__mapper_args__ = {'polymorphic_identity': 'Information'}
class Widget(Node):
__tablename__ = 'Widget'
id = Column(Integer, ForeignKey('Node.ID'), primary_key=True)
Name = Column(Text)
UnitType = Column(Text)
Amount = Column(Float)
_Number = Column('Number', Float)
__table_args__ = (ForeignKeyConstraint(
['Name', 'Number'],
['Information.Name', 'Information.Number']),
{})
__mapper_args__ = {'polymorphic_identity': 'Widget'}
я волновалась это дало бы мне циклические ссылку вопросы, но вместо этого он дает мне эту ошибку:
InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: Could not determine join condition between parent/child tables on relationship Widget.Information - there are multiple foreign key paths linking the tables. Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference to the parent table.
Я попытался добавить foreign_keys аргументов отношений, как на виджете и побочной информации, но я получаю ту же ошибку. Может ли кто-нибудь помочь?