python - 无法确定关系上的父/子表之间的连接条件
问题描述
我有以下 sqlite3 数据库 Sqlite 数据库
我想将上面的表格映射到 python 代码。我的代码是
class Attendance(db.Model):
Id = db.Column(db.Integer, primary_key=True)
day = db.Column(db.Date)
employee = db.Column(db.Text)
def __init__(self, day,employee):
self.day = day
self.employee = employee
def __repr__(self):
return '<Employee %r>' % self.employee
class AttendanceActions(db.Model):
Id = db.Column(db.Integer, primary_key=True)
attendance_id = db.Column(db.Integer, db.ForeignKey('Attendance.Id'))
attendance = db.relationship('Attendance', backref='AttendanceActions', lazy='dynamic')
action_time = db.Column(db.DateTime)
action = db.Column(db.Text)
def __init__(self, attendance, action_time, action):
self.attendance = attendance
self.action_time = action_time
self.action = action
def __repr__(self):
return '<AttendanceAction %r>' % self.action_time
我得到了错误:
sqlalchemy.exc.NoForeignKeysError: Could not determine join condition between parent/child tables on relationship AttendanceActions.attendance - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
解决方案
推荐阅读
- dom - DOM HTML 中的“HTML 编程 API”是什么意思?
- c - 理解 K&R 的 putc 宏:K&R 第 8 章(Unix 系统接口)练习 2
- python - 在 Pandas DataFrame 中反转列顺序的大 O 复杂度是多少?
- python - 将网络浏览器数据发送到另一个网络浏览器。(蟒蛇首选)
- r - choroplethrZip 返回“无法添加绑定”字幕错误 - 即使使用示例代码
- javascript - 关键帧背景图像动画不使用预加载图像
- ruby - 在 ruby 中将数据写入 csv 文件的问题
- python - 为 Keras 中的某些张量元素分配新值
- r - 累积对数正态函数不返回正确的概率
- c# - 发送到 Azure 事件中心错误