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