如何更正此 sqlalchemy.exc.NoForeignKeysError?
How do I correct this sqlalchemy.exc.NoForeignKeysError?
为什么我会得到 TraceBack
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition
between parent/child tables on relationship County.Legislators -
there are no foreign keys linking these tables.
Ensure that referencing columns are associated with a
ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
具有以下型号:
class County(Base):
__tablename__ = 'tblCounty'
CountyCode = Column('CountyCode', String, primary_key=True)
Legislators = relationship('Legislators', backref='County', lazy='dynamic')
class Legislators(Base):
__tablename__ = 'VLegislators'
EmployeeNo = Column('EmployeeNo', String, primary_key=True)
CountyCode = Column('CountyCode', String, ForeignKey('County.CountyCode'))
我正在尝试映射新罕布什尔州提供的面向 MS SQL 的 public 数据库。所以不允许架构更改。
为什么在 class 立法者中明确定义了外键关系却抱怨缺少外键关系?
据我所知,您应该在 ForeignKey 中使用表名:
CountyCode = Column('CountyCode', String, ForeignKey('tblCounty.CountyCode'))
为什么我会得到 TraceBack
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition
between parent/child tables on relationship County.Legislators -
there are no foreign keys linking these tables.
Ensure that referencing columns are associated with a
ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
具有以下型号:
class County(Base):
__tablename__ = 'tblCounty'
CountyCode = Column('CountyCode', String, primary_key=True)
Legislators = relationship('Legislators', backref='County', lazy='dynamic')
class Legislators(Base):
__tablename__ = 'VLegislators'
EmployeeNo = Column('EmployeeNo', String, primary_key=True)
CountyCode = Column('CountyCode', String, ForeignKey('County.CountyCode'))
我正在尝试映射新罕布什尔州提供的面向 MS SQL 的 public 数据库。所以不允许架构更改。
为什么在 class 立法者中明确定义了外键关系却抱怨缺少外键关系?
据我所知,您应该在 ForeignKey 中使用表名:
CountyCode = Column('CountyCode', String, ForeignKey('tblCounty.CountyCode'))