How to have two models reference each other Django

The Django documentation for the ForeignKey field states:

If you need to create a relationship on a model that has not yet been defined, you can use the name of the model, rather than the model object itself.

So in your case, that would be:

class Game(models.Model):
    # Other fields...
    on = models.ForeignKey('Member', blank = True)

class Member(models.Model):
    # Other fields...
    game = models.ForeignKey(Game)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)