galbangi

galbangi

[error] ** (Ecto.NoPrimaryKeyValueError) struct while updating. insert working fine

i am trying to update record. its giving me error. on insert its working fine.

[error] ** (Ecto.NoPrimaryKeyValueError) struct %ShopRestApis.Schema.CustomerSchema{__meta__: #Ecto.Schema.Metadata<:built, "customer">, id: nil, first_name: nil, last_name: nil, address: nil, landmark: nil, city: nil, state: nil, postcode: nil, type: nil, status: nil, mobile: nil, phone: nil, email: nil, company_name: nil, tax_code: nil, jobs: nil, inserted_at: nil, updated_at: nil} is missing primary key value
(ecto 3.12.2) lib/ecto/repo/schema.ex:1078: anonymous fn/3 in Ecto.Repo.Schema.add_pk_filter!/2

but i have id in changes

[(shop_rest_apis 0.1.0) lib/shop_rest_apis/context/customer_context.ex:67: ShopRestApis.Context.CustomerContext.update/2]
value #=> #Ecto.Changeset<
  action: nil,
  changes: %{
    id: "27efc595-dba9-4d9a-8a16-a4fd0d733c17",
    status: "Active",
    type: "Private",
    mobile: "+39,350577777",
    first_name: "test"
  },
  errors: [],
  data: #ShopRestApis.Schema.CustomerSchema<>,
  valid?: true,
  ...
>

my update function

  def update(%CustomerSchema{} = data, attrs) do
    data
    |> CustomerSchema.changeset(attrs)
    |> Repo.update()
  end

controller

def update(conn, params) do
    customer =
      ContextAliasController.get!(params["id"])

    with {:ok, %SchemaAliasController{} = customer} <-
           ContextAliasController.update(
             customer,
             params
           ) do
      render(conn, :show, customer: customer)
    end
  end

on schema i have uuid as primary key

  @primary_key {:id, :binary_id, autogenerate: false}
  @foreign_key_type :binary_id

Marked As Solved

al2o3cr

al2o3cr

Update isn’t going to work unless you use the first argument to changeset :stuck_out_tongue:

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement