如何实现用户对帖子点赞功能?我遵循了其他在线用户发布的代码;但是,我收到以下错误:
AmbiguousForeignKeysError:
Could not determine join condition between parent/child tables on relationship
User.posts - there are multiple foreign key paths linking the tables. Specify
the 'foreign_keys' argument, providing a list of those columns which should be
counted as containing
Run Code Online (Sandbox Code Playgroud)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
posts = db.relationship('Post', backref='author', lazy=True)
def __repr__(self):
return "{}, {}, {}".format(self.username, self.email, self.image_file)
liked = db.relationship( …Run Code Online (Sandbox Code Playgroud)