Ecto no default id column error 42703

Hello,

I’m using ecto 2.2.10.
I have defined a migration like this:

      def change do
    create table(:user_rooms, primary_key: false) do
      add :user_id, references(:users, on_delete: :delete_all), primary_key: true, null: false
      add :room_id, references(:rooms, on_delete: :delete_all), primary_key: true, null: false

      timestamps()
    end

    create index(:user_rooms, [:user_id])
    create index(:user_rooms, [:room_id])
    create index(:user_rooms, [:user_id, :room_id], unique: true)
  end

But, when I try to insert a changeset in my databse I get the following error:

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

I don’t know why. Thanks for help !

How does your schema looks like? You need to opt out from the I’d column there as well.

See the schema options here. You want to set @primary_key.

1 Like