Search code examples
djangodjango-modelspython-3.6

django.contrib.auth.models.DoesNotExist: User matching query does not exist


I tried to create an instance of a user in python shell using the following commands.

from django.contrib.auth.models import User
User.objects.all()
<QuerySet [<User: admin>]>
me = User.objects.get(username='rohan')

After which I got the following errors. Can someone please help.

 Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
        return getattr(self.get_queryset(), name)(*args, **kwargs)
      File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\query.py", line 380, in get
        self.model._meta.object_name
    django.contrib.auth.models.DoesNotExist: User matching query does not exist.

Solution

  • You have no User with username rohan. You seems to have a user with username admin though.

    me = User.objects.get(username='admin')