S
S
sortfact3332021-03-20 20:49:48
Django
sortfact333, 2021-03-20 20:49:48

Why am I getting UNIQUE constraint failed: offers_offer.currencyId_id?

I filter xml model and save it like this

try:
    # check model
    offer = Offer.objects.get(id = lxml_id)

    currencyId = host_ip.find('currencyId').text
    print(currencyId)
    currency = Currency.objects.get(name = currencyId)
    print(offer.currencyId)
    if not offer.currencyId == currencyId:
      offer.currencyId = currency
      save_model = True
    
    if save_model:
      offer.save()
      print('save 3')


But I get UNIQUE constraint failed: offers_offer.currencyId_id
How can I fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2021-03-20
@bacon

The database already has an offer record with currencyId equal to currency

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question