Perché ottengo il 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.
Come posso correggere questo sqlalchemy.exc.NoForeignKeysError?
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'))
Sto cercando di mappare un database pubblico di fronte a MS SQL fornite dallo Stato del New Hampshire. Quindi non sono consentite modifiche allo schema.
Perché lamentarsi della mancanza di una relazione ForeignKey quando si è chiaramente definiti nella classe Legislatori?
l'errore è del tutto su come configurare l'ORM; in questa fase (o in qualsiasi fase) SQLA non sa né si preoccupa di ciò che FK è fisicamente nel db – Eevee
nota che dato che stai fornendo esplicitamente i nomi delle colonne comunque, potresti usare nomi di attributi come 'country_code' che leggono più naturalmente come attributi in Python – Eevee