LL
mix dialyzer
запускалась с MIX_ENV=test
(подобно тому, как это делает mix test
)?Size: a a a
LL
V
mix dialyzer
запускалась с MIX_ENV=test
(подобно тому, как это делает mix test
)?LL
mix dialyzer
запускалась с MIX_ENV=test
(подобно тому, как это делает mix test
)?MIX_ENV=test mix dialyzer
?V
MIX_ENV=test mix test
LL
PG
preferred_cli_env: [dialyzer: :test]
PG
LL
preferred_cli_env: [dialyzer: :test]
V
IK
IK
DI
m
M
def insert(params) do
%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
it) 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.
Где
LL
LL
unique_constraint
нужно чтобы в базе был индекс users_chat_id_index
M
Repo.insert()
вернул {:error, %User{...}}M
name: :users_chat_id_index
в unique_constraint
LL
SM
def insert(params) do
%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
it) 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