How to modify reference primary keys in join table

Hello, I’m currently trying to alter a join table and add on_delete: :delete_all to the primary keys, because I’m restricted from deleting/updating any objects from both sides of the join.
This is how my alternation currently look like.

      modify(:autopost_channel_id, references("autopost_channels", on_delete: :delete_all),
        from: references("autopost_channels")

      modify(:tag_id, references("tags", on_delete: :delete_all), from: references("tags"))

Both columns are primary keys and there is no autogenerated primary key. The values for :from are type types of the current columns. I added it, because I read here that doing so tries to drop the FK table constraints, but I still get an error because of the constraints:

** (Postgrex.Error) ERROR 42710 (duplicate_object): constraint "autopost_channels_tags_autopost_channel_id_fkey" for relation "autopost_channels_tags" already exists

Which leads to my Question, how do I modify these columns like this?

Table definition for completeness:

    create table("autopost_channels_tags", primary_key: false) do
      add(:autopost_channel_id, references("autopost_channels"), primary_key: true)
      add(:tag_id, references("tags"), primary_key: true)
      add(:type, :boolean)


Solved with external help

1 Like