Need help creating a one-to-many relationship involving multiple foreign keys #13382
Unanswered
Lesamuen
asked this question in
Usage Questions
Replies: 1 comment 3 replies
-
|
you want that "chips" relationship to refer to "chips.owner_id" as you saw but you need to refer to it correctly, the most direct way is like this: these work also: or even: hope this helps |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
This is in Python 3.14.6 with SQLAlchemy 2.0.50 and using sqlite3 as an engine.
I'm making a data structure for a special online casino where currency is specially tied to the players they originated from.
It involves 3 objects: the games, the players (multiple players per game, but a user can be a part of multiple games at once, hence 2 primary keys), and the chips/currencies (tied to a game, and one player holds chips from another player, hence 3 primary keys).
The only code that's running is
The main problem is Player.chips; it keeps giving an AmbiguousForeignKeysError no matter what I do.
AmbiguousForeignKeysError: Could not determine join condition between parent/child tables on relationship Player.chips - 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 a foreign key reference to the parent table.I've tried:
and
Those should be more correct, considering it needs to select for the same game id as well. But they still give me the same error, so the error must be on Player.chips itself.
However, when I try:
OR
they give me a different error:
AttributeError: 'Table' object has no attribute 'owner_id'and I simply have no idea how to even interpret that, considering I can see owner_id defined right there.
Please help me make sense of this.
Beta Was this translation helpful? Give feedback.
All reactions