Cast_embed followed by unique_constraint doesn't detect uniqueness errors

As @joey_the_snake mentioned, unique_constraint/3 only adds the error if your changest hits the database. You can however add an unsafe_validate_unique/4 to optimistically check for duplicate entries before insertion and add an error to the changeset if a duplicate is found. This is useful to show the user early on that the operation can’t succeed (and will probably catch most of the cases, the rest will be caught by unique_constraint/3)