No function clause matching in Ecto.Changeset.put_change/3

Hi Everyone!
I have been getting into Elixir and most recently Phoenix. I am running into an issue though trying to build a website with Phoenix. I want to change one field in my changeset struct, which I am using put_change for, however, I get the error that is in the title. I am not really sure what I am doing wrong and have searched everywhere for the error.

I am sure its probably something simple I just can’t seem to figure it out. Thanks for your help and the code snippet is below!

def update(conn, %{"id" => id, "artist" => artistParams}) do
    if upload = artistParams["img"] do
      extension = Path.extname(upload.filename)
      #temporary for dev
      File.cp(upload.path, "redacted")
      #artistParams = Artist.changeset(%Artist{},%{img: "/artistimg/"<>id<>"profile"<>extension})
    artistParams = Ecto.Changeset.put_change(artistParams, :img, "test");
    artist = Artists.getArtist(id)
1 Like

Hello and welcome,

This code looks wrong…

This require a changeset, but You pass attributes


Also it seems You are using one context for Artist Struct…

Maybe like this.

|> Artists.getArtist()
|> Ecto.Changeset.change(%{img: "test"})
|> Repo.update()

Thank you! This helped fix my issue, I was just thinking about it in the wrong way!

1 Like