Ecto is throwing me the following error:
** (exit) an exception was raised:
** (Ecto.ConstraintError) constraint error when attempting to insert struct:
* unique: res_users_login_key
If you would like to convert this constraint into an error, please
call unique_constraint/3 in your changeset and define the proper
constraint name. The changeset defined the following constraints:
* unique: res_users_login_index
Do I understand correctly that the actual name of the constraint in postgresql determines if the unique_constraint/3 function is successful or not? Just for reference, in postgreSQL the constraint is defined as follows:
Indexes:
"res_users_pkey" PRIMARY KEY, btree (id)
"res_users_login_key" UNIQUE CONSTRAINT, btree (login)
so _key and not _index.
I call the constraint function as follows:
changeset |> unique_constraint(:login)
So, how do I make this work?
|> unique_constraint(:login, [name: :res_users_login_index]).|> unique_constraint(:login, [name: :res_users_login_key])?_key._indexis the incorrect name used by default since you hadn't specified aname._indexseems to be an inappropriate default doesn't it? Seems_keywould be better for unique constraints.unique_indexin Ecto migrations use the_indexsuffix for the index names by default.