'qlalchemy.exc.AmbiguousForeignKeysError: Could not determine join condition between parent/child tables on relationship Users.rater

i am trying to create function in FLASK and html page to allow users to rate each other - one user can give rating to enother user, but i am getting this error: sqlalchemy.exc.AmbiguousForeignKeysError. Does anyone know, how to solve it please?

    class Users(db.Model, UserMixin):
        id = db.Column(db.Integer, primary_key = True)
        username = db.Column(db.String(20), nullable=False, unique=True)
        name = db.Column(db.String(200), nullable = False)
        email = db.Column(db.String(120), nullable = False, unique = True)
        date_added = db.Column(db.DateTime, default = datetime.utcnow)
        password_hash = db.Column(db.String(128))
        posts = db.relationship('Posts', backref='poster')
        place = db.Column(db.String(128))
        rater = db.relationship('Ratings', backref='rater')
        rated = db.relationship('Ratings', backref='rated')

class Ratings(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String(200))
    from_user = db.Column(db.Integer, db.ForeignKey('users.id'))
    to_user = db.Column(db.Integer, db.ForeignKey('users.id'))

@app.route('/user/<int:id>/add-rating/', methods=['GET', 'POST'])
def rating(id):
    form = RatingForm()
    to_user = Users.query.get_or_404(id)
    if form.validate_on_submit():
        from_user = current_user.id
        content = form.content.data
        rating = Ratings(from_user=from_user, to_user=to_user, content=content)
        db.session.add(rating)
        db.session.commit()
        flash(' posted')
    return render_template('add_rating.html', form=form, to_user=to_user)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source