TransactionManagementError An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block. django project
I would like to add products or update them if they exist on the database. the data collected comes from an API, then I save it on my database that I created.
models.py
class Holl(models.Model):
name=models.CharField(max_length=70,blank=True,null=True)
service=models.CharField(max_length=255,blank=True,null=True)
section=models.CharField(max_length=70,blank=True,null=True)
class Meta:
constraints=[
models.UniqueConstraint(fields=['name', 'section'], name='unique_rows')
]
views.py
url='http://myAPI/Holl/GetHoll'
x=requests.get(url)
contenu=x.json()
all_holls=contenu['comm']
for holl in all_holls:
ins, _ = Holl.objects.update_or_create(name=holl['name'],service=holl['service'],
section=holl['section'],defaults={'name':holl['name'],'service':holl['service'],'section':holl['section']})
ins.save()
After testing I get this error:An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.