# Saving of Many to Many object doesn't work correctly

**URL:** <https://forum.djangoproject.com/t/saving-of-many-to-many-object-doesnt-work-correctly/28557>\
**Category:** Mystery Errors\
**Created:** [February 29, 2024, 4:08pm UTC](https://forum.djangoproject.com/t/saving-of-many-to-many-object-doesnt-work-correctly/28557 "2024-02-29T16:08:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lzednik](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lzednik/32/18420_2.png) [@lzednik](https://forum.djangoproject.com/u/lzednik)\
**Post date:** [February 29, 2024, 4:08pm UTC](https://forum.djangoproject.com/t/saving-of-many-to-many-object-doesnt-work-correctly/28557/1 "2024-02-29T16:08:25Z")

</div>

In simplified form, I have two models:

```auto
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

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 29, 2024, 4:17pm UTC](https://forum.djangoproject.com/t/saving-of-many-to-many-object-doesnt-work-correctly/28557/2 "2024-02-29T16:17:56Z")

</div>

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.
