Changeset validations doesn't work with ecto multi?

I have a small problem, could help me ?

I created a registration form, where the user fills in and are inserted in 2 different tables, using ecto.multi.insert …
So far so good, everything working perfectly …

The problem I’m experiencing is …
Changetset validations are not working,
can you help me?
Any would be the best way to make this work?

Below is the code.


  def create(conn, %{"teste" => teste_params}) do
      current_user = Pow.Plug.current_user(conn)
      dbhost_page = Map.get(teste_params, "column1")
      dbname_page = Map.get(teste_params, "column2")
      dbpasswd_page = Map.get(teste_params, "column3")
      languagecode_page = Map.get(teste_params, "column4")
      name_page = Map.get(teste_params, "column5")
      status_page = Map.get(teste_params, "column6")
      id_page = Map.get(teste_params, "column7")

    multi =
    |> Multi.insert(:database, %Database{column1: dbhost_page, column2: dbname_page, column3: dbpasswd_page, column4: column1})
    |> Multi.insert(:website, %Website{column5: name_page, column6: languagecode_page, column7: status_page, column8: id_page, user_id:})
    # require IEx;IEx.pry

    case Repo.transaction(multi) do

      {:ok, teste} ->
        |> put_flash(:info, "criado com sucesso!")
        |> redirect(to: "/testes")

      {:error, changeset} ->
        render(conn, "new.html", changeset: changeset)

Changeset 1 (database)

  def changeset(database, attrs) do
    |> cast(attrs, [:column1, :column2, :column3, :column4])
    |> validate_required([:column1, :column2, :column3, :column4])

Changeset 2 (teste)

  def changeset(teste, attrs) do
    |> cast(attrs, [:column5, :column6, :column6, :column7, :column8, :column9])
    |> validate_required([:column5, :column6])
    |> unique_constraint(:column5, message: "Nome do Projeto já existe")

How do I run these validations with Ecto.Multi?

can you help me?

You don’t need to unpack parameters manually like this, that’s what Ecto.Changeset.cast does.

Ecto.Multi.insert does exactly what you tell it to - it inserts the struct or changeset provided. If you want to use the changeset function, call it:

database_changeset = Database.changeset(%Database{}, teste_params)
website_changeset = Website.changeset(%Website, teste_params)

multi =
  |> Multi.insert(:database, database_changeset)
  |> Multi.insert(:website, website_changeset)

thank you very much, that really was it.