Link to home
Start Free TrialLog in
Avatar of coder
coderFlag for Australia

asked on

Django model key error

Hi Experts,

I get the following error when I run the python application.

The code which is causing error is as follows:

 current = Item.objects.filter(pk=str(properties['id'])).first()

Open in new window


where Item is a Django model and id is the primary key .  the error which i get is as follows:-

KeyError: 'id'

Traceback (most recent call last):
  File "/home/ubuntu/workarea/dev-harvestor/harvestor-2/harvest-territory-stories/harvest/models.py", line 283, in _add_item
    current = Item.objects.filter(pk=str(properties['id'])).first()
KeyError: 'id'

Open in new window

I am not getting what is causing this error.  Please help in resolving this issue.

Thank you,
Avatar of coder
coder
Flag of Australia image

ASKER

Hi All,

I get the same error when I change the code to like this

  File "/home/ubuntu/workarea/dev-harvestor/harvestor-2/harvest-territory-stories/harvest/models.py", line 284, in _add_item
    nCount = Item.objects.filter(pk=str(properties['id'])).count()
KeyError: 'id'

Open in new window


Please help me in resolving this issue.
Avatar of coder

ASKER

Hi

I get the same error, When  I try following

Traceback (most recent call last):
  File "/home/ubuntu/workarea/dev-harvestor/harvestor-2/harvest-territory-stories/harvest/models.py", line 294, in _add_item
    if Item.objects.filter(pk=str(properties['id'])).exists():
KeyError: 'id'

Open in new window


How to resolve this issue?  please help me
ASKER CERTIFIED SOLUTION
Avatar of coder
coder
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial