Ecto.Repo.insert with id

I want to generate id by myself and also want the insert with auto id if not provide. Any ways to do this?

Have you tried something that didn’t work? I can’t think of any major pitfalls.

Casting the :id field in your changeset should do the trick

3 Likes

I did this but not working:

attrs =
  attrs
  |> Map.put("input_date", yymmdd)
  |> Map.put("name", name)
  |> Map.put("id", sf_id)

Sorry, adding to cast actually works:

|> cast(attrs, [:id, 

Thanks