小编aj3*_*409的帖子

AmbigeousForeignKeysError:无法确定关系 User.posts 上父/子表之间的联接条件 - 多个外键路径

如何实现用户对帖子点赞功能?我遵循了其他在线用户发布的代码;但是,我收到以下错误:

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)

python sqlalchemy flask flask-sqlalchemy

3
推荐指数
1
解决办法
3355
查看次数

标签 统计

flask ×1

flask-sqlalchemy ×1

python ×1

sqlalchemy ×1