'Flask sqlalchemy: how to draw two foreign key relationships to the same table
How would I go about creating the foreign key relationships for a very simple friend request database schema in flask sqlalchemy. Both the requester and requestee will be foreign keys in the Friendships table. Though my current version will not work because it throws an error.
class User(db.Model):
id = db.Column(db.Integer, primary_key = True)
email = db.Column(db.String(255), unique=True)
password = db.Column(db.String(255))
state = db.Column(db.String(255))
friend = db.relationship("Friendship", backref = "user")
class Friendship(db.Model):
id = db.Column(db.Integer, primary_key = True)
Requester = db.Column(db.Integer, db.ForeignKey("user.id"))
Requestee = db.Column(db.Integer, db.Foreignkey("user.id"))
status = db.Column(db.Integer)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
