title: SQLAlchemy | Multiple One-To-One and One-To-Many relationships
body: <p>I've got two models: Game and Player. I want to have a list of all players in the Game Model, as well as one of these players in a different field. It's a flask server and a sqlite database.</p>
  <p>Here is my Player Model:</p>
  <pre class="lang-py prettyprint-override"><code>class Player(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      # other fields...
      
      game_id = db.Column(db.Integer, db.ForeignKey('game.id'))
      game = db.relationship('Game', back_populates='players', foreign_keys=game_id)
  </code></pre>
  <p>Here is my Game Model:</p>
  <pre class="lang-py prettyprint-override"><code>class Game(db.Model):
      id = db.Column(db.Integer, primary_key=True)
      # other fields...
  
      current_president_id = db.Column(db.Integer, db.ForeignKey('player.id'))
      current_president = db.relationship(&quot;Player&quot;, foreign_keys=current_president_id)
  
      # other one-to-one relationships to the Player Model, exactly like the first one...
  
      players = db.relationship('Player', back_populates='game', foreign_keys=Player.game_id)
  </code></pre>
  <p>I made the two models based on <a href="https://stackoverflow.com/a/52059318/14598147">this Response</a>. But I still get the same Warning:</p>
  <pre><code>SAWarning: Cannot correctly sort tables; there are unresolvable cycles between tables &quot;game, player&quot;, which is usually caused by mutually dependent foreign key constraints.  Foreign key constraints involving these tables will not be considered; this warning may raise an error in a future release.
  </code></pre>
  <p>Like the Warning says, when using this configuration I then get at some point:</p>
  <pre><code>sqlalchemy.exc.CircularDependencyError: Circular dependency detected. (SaveUpdateState(&lt;Game at 0x23009e00160&gt;), SaveUpdateState(&lt;Player at 0x23009e141c0&gt;), ProcessState(ManyToOneDP(Game.current_president), &lt;Game at 0x23009e00160&gt;, delete=False), ProcessState(OneToManyDP(Game.players), &lt;Game at 0x23009e00160&gt;, delete=False))
  </code></pre>
  <p>I have no idea what to do, I tried to read through the documentation and tested many other configurations, but nothing works. All help greatly appreciated. Thanks!</p>