Python 为什么我会得到;InvalidRequestError";?

Python 为什么我会得到;InvalidRequestError";?,python,sqlalchemy,Python,Sqlalchemy,根据ORM教程,我尝试使用联接在表和查询之间实现一些外键: from sqlalchemy import (Column, ForeignKey, Integer, create_engine) from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, relationship Base = declarative_base() class DataAcce

根据ORM教程,我尝试使用联接在表和查询之间实现一些外键:

from sqlalchemy import (Column, ForeignKey, Integer, create_engine)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship

Base = declarative_base()

class DataAccessLayer():

    def __init__(self):
        conn_string = "mysql+mysqlconnector://root:root@localhost/"
        self.engine = create_engine(conn_string)

    def create_session(self):
        Base.metadata.create_all(self.engine)
        Session = sessionmaker()
        Session.configure(bind=self.engine)
        self.session = Session()

class Bet(Base):

    __tablename__ = "bet"
    __table_args__ = ({"schema": "belgarath", "extend_existing": True})

    id_ = Column(Integer, primary_key=True)
    match_id = Column(Integer, ForeignKey("belgarath.match_.id_"))

    match_ = relationship("Match", back_populates="belgarath.bet")

class Match(Base):
    __tablename__ = "match_"
    __table_args__ = ({"schema": "belgarath", "extend_existing": True})

    id_ = Column(Integer, primary_key=True)
    tournament_id = Column(Integer)= Column(Integer)

dal = DataAccessLayer()
dal.create_session()

bets = dal.session.query(Bet)
bets.join(Match)
for bet in bets:
    print(bet.id_, bet.tournament_id = Column(Integer))
但是,我在
bets=dal.session.query(Bet)
行中遇到以下错误:

Exception has occurred: InvalidRequestError
Mapper 'mapped class Match->match_' has no property 'belgarath.bet'

我哪里做错了?在
Match
中是否需要某种对等关系?

您是否已经尝试将
back\u populates
更改为
back\u ref
。您好。我得到了以下错误:
TypeError:relationship()得到了一个意外的关键字参数“back\u ref”
对不起,我搞错了<代码>反向参考非
反向参考