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:

Last Post!

galbangi

galbangi

i dont know what to say. stupid mistake. thank you very much.

Where Next?

Popular in Questions Top

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
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement