gpt4 book ai didi

python - sqlalchemy.exc.MultipleResultsFound : Multiple rows were found when exactly one was required

转载 作者:行者123 更新时间:2023-12-05 04:50:04 27 4
gpt4 key购买 nike

我在数据库中有这样的结构

tasks_exams = db.Table('tasks_exams',
db.Column('task_id', db.Integer, db.ForeignKey('tasks.id')),
db.Column('exam_id', db.Integer, db.ForeignKey('exams.id'))
)

class Tasks(db.Model):
__tablename__ = 'tasks'

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
task = db.Column(db.Text)


class Exams(db.Model):
__tablename__ = 'exams'

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name_of_Exam = db.Column(db.String(140))
number_of_exam_task = db.Column(db.SmallInteger)
name_of_exams_task = db.Column(db.String(140))

tasks = db.relationship('Tasks',
secondary=tasks_exams,
back_populates="exams")

我想获取 exams_1 所在的所有任务:

tasku = Exams.query.filter(Exams.name_of_Exam == "exams_1").scalar()

我得到一个错误:

sqlalchemy.exc.MultipleResultsFound: Multiple rows were found when exactly one was required

我该如何解决我的问题?

最佳答案

tasku = Tasks.query.filter(Exams.name_of_Exam =="ЕГЭ").all()

关于python - sqlalchemy.exc.MultipleResultsFound : Multiple rows were found when exactly one was required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67382183/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com