I need to create a table under the name of friends , it should look like this:
friends:
I tried to do this with tutorials from SQLALchemy, but I did not find how to make many-to-many relationships for a single table.
Here is what I tried:
_friends = db.Table('friends',
db.Column('user_id', db.Integer, db.ForeignKey('users.id')),
db.Column('friend_id', db.Integer, db.ForeignKey('users.id'))
)
class User(db.Model, UserMixin):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(255), unique=True)
password = db.Column(db.String(255))
categories = relationship("Category")
cards = relationship("BusinessCard")
friends = db.relationship(
'User',
backref="users",
secondary=_friends
)
He says:
AmbiguousForeignKeysError: / User.friends - , "". "foreign_keys", .
- , ?