Employee matching query does not exist

90 views
Skip to first unread message

yassin kamanyile

unread,
Jan 4, 2022, 9:36:25 AM1/4/22
to Django users
please team ..i  got an error from that line below

obj.employee = Employee.objects.get(name=self.request.POST.get('employee_id'))

Jitendra kumar Patra

unread,
Jan 4, 2022, 9:44:55 AM1/4/22
to django...@googlegroups.com
name column row's data not matching from database

Show that you are getting error .


So we use the Expection then you can easily handle the error ..

On Tue, 4 Jan 2022, 8:05 pm yassin kamanyile, <yassi...@gmail.com> wrote:
please team ..i  got an error from that line below

obj.employee = Employee.objects.get(name=self.request.POST.get('employee_id'))

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0d469b11-33f5-49bb-a984-76f53a2e08c8n%40googlegroups.com.

Rey Ondiyo

unread,
Jan 5, 2022, 8:53:30 AM1/5/22
to Django users
Django don't saw a employe who have this ID
 so you can use filter if there's not matching in your database he return [ ]. 

obj.employee= Employee.objects.filter(name=self.request.POST.get('employee_id'))

Julio Cojom

unread,
Jan 5, 2022, 9:15:04 AM1/5/22
to django...@googlegroups.com
Hi, 

Try the following.

employee =self.request.POST.get('employee_id')
print(employee)
obj.employee= Employee.objects.filter(name=employee)

It will crash again, but you can see in the console if it's printing the id correctly.

I've assume this is a function, not a class view by the way that you are handling the query set. And I believe with the poor information that you give us, that the 'employee_id' isn't the right keyword to get the value desired.

Usually you can use the name in your models to refer to the field that you want the data. If you want the primary key, you should use pk of an existing record in the database.

Also you can print self.request.POST to see all the data that I has, that is a dictionary so you can see they keyword you need and the data in brings.

Regards.

Julio Cojom.






Gwanghyeon Gim

unread,
Jan 5, 2022, 9:18:15 AM1/5/22
to Django users
Two possible scenarios.

1. self.request.POST doesn't have any key named 'employee_id', so self.request.POST.get('employee_id') returns None
2. self.request.POST.get('employee_id') has value like 'Sam', but Employee model doesn't have any object whose name equals to self.request.POST.get('employee_id').
Reply all
Reply to author
Forward
0 new messages