коллеги,всех приветствую!
У меня следующий вопрос. Я хочу в рамках одной таблицы создать связь "многие ко многим".
У меня есть таблица USer, которая состоит из двух столбцов
id_user name_user
1 Vova
2 Vania
3 Dasha
4 Katya
5 Sasha
.......................
У меня стоит задача соединить двух пользователей. Если я верно понял,для этого надо создать вторую таблицу связей:
id_user_1 id_user_2
1 2
1 3
3 5
............................
Как я пытаюсь решитб проблему:
users_relation = db.Table(
"users_relation",
db.Column("user_id_1", db.Integer, db.ForeignKey("
users.id")),
db.Column("user_id_2", db.Integer, db.ForeignKey("
users.id"))
)
class User(db.Model):
tablename = "users"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
users = db.relationship(
"User",
secondary=users_relation,
back_populates="users"
)
Получаю ошибку:
sqlalchemy.exc.AmbiguousForeignKeysError: Could not determine join condition between parent/child tables on relationship User.users - there are multiple foreign key paths linking the tables via secondary table 'users_relation'. Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference from the secondary table to each of the parent and child tables.
Как можно решить данную проблему?