Saving of Many to Many object doesn't work correctly

In simplified form, I have two models:

class Chart(models.Model):
    barcode = models.CharField()

class Visit(models.Model):
    chart = models.ManyToManyField('Chart')

I would like to add a new chart to an existing visit.

I have the correct visit object and I created a new chart object

visit_obj = Visit.objects.get(pk=visit_pk)
print('visit id', visit_obj.id) #this is correct

new_chart = Chart()
new_chart.barcode = 'something'
new_chart.save()
print('new_chart id', new_chart.id)

I add the chart to the visit:

visit_obj.chart.add(new_chart)

Two things happen:

  1. The primary key on the new_chart object is not new. It is an ID that has been created and now there are two objects with that ID.

  2. The crosswalk table between the two models shows that a new record got inserted with the chart_id that belongs to the new chart (and also an old chart), but the visit_id is completely wrong. It doesn’t match the visit_id from my visit_obj.

I am using Snowflake as my database.

I am completely baffled and would appreciate help.

Thank you

Snowflake is not one of the officially supported databases in Django.

For us to consider this to be a Django issue, you’ll need to recreate this on one of the supported databases. Otherwise, I would suggest you raise this issue with the authors of the Django database engine being used.