Reputation: 307
I have a player table which uses the user id from auth_user table as the foreign key, and I have a view function checking whether the player already exists:
def index(request):
try:
player = models.Player.objects.get(player_user_id=request.user)
logger.debug('found player')
except:
logger.debug('player doesn\'t exist!')
player = models.Player(player_user_id=request.user, player_isconsented=True, player_isactive=True, player_deactivated_ts=None)
player.save()
but every time a new player is created it seems to cover the old player row. And there is only one row existing in the player table although there are multiple users. Any thoughts? much appreciated.
Upvotes: 0
Views: 30
Reputation: 10389
I think the core of your problem is that you're catching ALL exceptions, rather than a specific one. If you
except Player.DoesNotExist:
I bet your program will fail with a different exception, and all will become clear.
Upvotes: 1