(ArgumentError) cast/3 expects a list of atom keys, got: `{:updated_at, :naive_datetime}

Ecto 3.6, Ecto_sql 3.6 also

My User data-module:

  # [........]

  @changeset_fields [

  def changeset(this, params \\ %{}) do
    cast(this, params, @changeset_fields)
    |> validate_required([


    defmodule MyAp.Repo.Migrations.CreateUsers do
      use Ecto.Migration

      def change do
        create table(:users) do
          # [......]

        # [......]

And whenever I’m trying to insert a new user:

    a1 = Repo.insert!(User.changeset(%User{}, %{
      email: "email",
      status: :active,
      confirmed_at: DateTime.utc_now()

it’ll always throw an exception:

    ** (ArgumentError) cast/3 expects a list of atom keys, got: `{:updated_at, :naive_datetime}`
        (ecto 3.6.2) lib/ecto/changeset.ex:563: Ecto.Changeset.cast_key/1
        (ecto 3.6.2) lib/ecto/changeset.ex:521: Ecto.Changeset.process_param/7
        (elixir 1.11.3) lib/enum.ex:2193: Enum."-reduce/3-lists^foldl/2-0-"/3
        (ecto 3.6.2) lib/ecto/changeset.ex:508: Ecto.Changeset.cast/6
        (my_app 0.1.2) lib/user.ex:42: MyApp.User.changeset/2

this happens only in User module, and in others not, although User is almost identical to other data-modules.

What’s the matter?

I can’t reproduce this error can you give full lines of codes, something you missed in question

Something in the code you omitted is responsible for the error.

1 Like

The error is on line 42 of the user file… And no context? Is that an old Phoenix version?

1 Like

The error you posted arises here:

permitted is the value passed into Ecto.Changeset.cast's third argument.

In the code you posted from your User schema, it appears this comes from @changeset_fields. Verify that that isn’t getting overwritten with a map or keyword list.

1 Like