Insert schema with composite key

Hey every one,

I have schema like this:

 create table(:test, primary_key: false) do
      add(
        :foo_id,
        references(:foo, on_delete: :delete_all),
        null: false,
        primary_key: true
      )

      add(:bar, :string, null: false, primary_key: true)

      add(:other_field, :string, null: false)

      timestamps()
    end

I’m trying to use insert but face with error like this:

** (Postgrex.Error) ERROR 42703 (undefined_column) column "id" does not exist

I used Repo.Insert(Test, returning: [:foo_id, :bar]) and also Repo.Insert(Test, returning: false) and still same result.

anyone have any idea on that?

Thanks.

1 Like

Did you set @primary_key false on the schema (/primary_key: true on the relationship)?

3 Likes

no, thanks. It works now.

2 Likes