"Key :model not found" error with latest Elixir/Phoenix

Hello!
I just (re)downloaded Elixir (v1.3.4) and Erlang (OTP 19) and Phoenix (v1.2.0)
After running the usual mix phoenix.new myapp and cd myapp, I ran mix phoenix.server, and it stopped at this compile error:

== Compilation error on file lib/phoenix_ecto/html.ex ==
** (KeyError) key :model not found in: %Phoenix.HTML.Form{data: nil, errors: {{:., [line: 12], [{:changeset, [line: 12], nil}, :errors]}, [line: 12], []}, hidden: [], id: {:name, [line: 10], nil}, impl: Phoenix.HTML.FormData.Ecto.Changeset, index: nil, name: {:name, [line: 11], nil}, options: [], params: %{}, source: {:changeset, [line: 8], nil}}
    (stdlib) :maps.update(:model, {:model, [line: 13], nil}, %Phoenix.HTML.Form{data: nil, errors: {{:., [line: 12], [{:changeset, [line: 12], nil}, :errors]}, [line: 12], []}, hidden: [], id: {:name, [line: 10], nil}, impl: Phoenix.HTML.FormData.Ecto.Changeset, index: nil, name: {:name, [line: 11], nil}, options: [], params: %{}, source: {:changeset, [line: 8], nil}})
    lib/phoenix_html/form.ex:170: anonymous fn/2 in Phoenix.HTML.Form.__struct__/1
    (elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
    expanding struct: Phoenix.HTML.Form.__struct__/1
    lib/phoenix_ecto/html.ex:7: Phoenix.HTML.FormData.Ecto.Changeset.to_form/2

Help is very much appreciated.

Edit: interesting enough, this is my mix help:

mix                   # Runs the default task (current: "mix run")
... # bunch of stuff
mix new               # Creates a new Elixir project
=> mix phoenix.new       # Creates a new Phoenix v1.1.4 application !!! wtf?
mix profile.fprof     # Profiles the given file or expression with fprof
mix run               # Runs the given file or expression
mix test              # Runs a project's tests
mix xref              # Performs cross reference checks
iex -S mix            # Starts IEx and runs the default task

The help says Phoenix v1.1.4, which… doesn’t make any sense.

Updating phoenix_ecto to 3.0 worked:

defp deps do                                                                                                                               
    [{:phoenix, "~> 1.2.1"},                                                                                                                 
     {:postgrex, ">= 0.0.0"},                                                                                                                
     {:phoenix_ecto, "~> 3.0"},                                                                                                              
     {:phoenix_html, "~> 2.4"},                                                                                                              
     {:phoenix_live_reload, "~> 1.0", only: :dev},                                                                                           
     {:gettext, "~> 0.9"},                                                                                                                   
     {:cowboy, "~> 1.0"}]                                                                                                                    
end

I remember there might be issues with and old Phoenix version staying in .mix after an Elixir version upgrade. Try looking into ~/.mix/archives and see if there are old versions there (probably safest to delete all of them and install latest Phoenix again).

You’ll probably see more explanations at https://github.com/phoenixframework/phoenix_html/issues/122

1 Like