%User{}
|> Ecto.Changeset.cast(initialize_params(params), [:chat_id, :first_name])
|> Repo.insert()
end
# user.ex
def changeset(user, attrs) do
user
|> cast(attrs, [:chat_id, :first_name])
|> validate_required([:chat_id])
|> unique_constraint(:chat_id, name: :users_chat_id_index)
end
Ошибка такая.
** (exit) an exception was raised:
** (Ecto.ConstraintError) constraint error when attempting to insert struct:
* users_chat_id_index (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 has not defined any constraint.
Где туплю?
Ты в insert/1 вызываешь не User.changeset/2, а Ecto.Changeset.cast
Обсуждают сегодня