** (Ecto.ConstraintError) constraint error when attempting to update struct:
* nick_name (unique_constraint)
If you would like to stop this constraint violation from raising an
exception and instead add it as an error to your changeset, please
call `unique_constraint/3` on your changeset with the constraint
`:name` as an option.
The changeset defined the following constraints:
* nick_name_or_id (unique_constraint)
code: {:error, error} = UserHandler.update_user(params)
stacktrace:
(ecto 3.4.4) lib/ecto/repo/schema.ex:700: anonymous fn/4 in Ecto.Repo.Schema.constraints_to_errors/3
(elixir 1.11.4) lib/enum.ex:1411: Enum."-map/2-lists^map/1-0-"/2
(ecto 3.4.4) lib/ecto/repo/schema.ex:685: Ecto.Repo.Schema.constraints_to_errors/3
(ecto 3.4.4) lib/ecto/repo/schema.ex:666: Ecto.Repo.Schema.apply/4
(ecto 3.4.4) lib/ecto/repo/schema.ex:348: anonymous fn/15 in Ecto.Repo.Schema.do_update/4
def changeset(user, params) do
cast(user, params, [
:id,
:email,
:first_name,
:last_name,
:nick_name,
])
|> unique_constraint([:nick_name, :id],
name: "nick_name_or_id",
match: :suffix,
message: "nick_name_or_id_already_taken"
)
help me out
what should be the name inside opts
my test is getting passed for name: “nick_name”
but getting the above error for name: “nick_name_or_id”