user = YourCustomUser.objects.get(username='your_username')
AuthToken.objects.all().delete()
token, created = AuthToken.objects.get_or_create(user=user)
token.token_key
Here the token will have empty strings for token_key, digest and salt fields when the AuthToken is created for that specific user for the first time. When you run the get_or_create command again, it returns the created Token without issues.
Of course, get_or_create throws error when multiple tokens exist for the User. Which is expected behaviour.
Also, in the admin interface, I cannot delete this bugged out token. Although I can use token.delete() in my Django shell.
Steps to reproduce: (in django shell)
Here the token will have empty strings for token_key, digest and salt fields when the AuthToken is created for that specific user for the first time. When you run the get_or_create command again, it returns the created Token without issues.
Of course, get_or_create throws error when multiple tokens exist for the User. Which is expected behaviour.
Also, in the admin interface, I cannot delete this bugged out token. Although I can use token.delete() in my Django shell.