[Solved]-Maximum recursion depth exceeded on Django model when creating

21👍

The problem is that you can’t access the team.players field when the Team instance is not yet saved to the database. Trying to do this will raise a ValueError.

However, while trying to raise this ValueError, the code will try to get a representation of your team object which will indirectly call unicode(team). This will try to access self.players, which will try to raise another ValueError before the first one is raised. This goes on until the maximum recursion depth is reached, but there is still no ValueError thrown. Therefore, you’ll only see the RuntimeError.

The same would (should?) happen if you did either of the following:

>>> team
>>> repr(team)
>>> unicode(team)
👤knbk

Leave a comment