title: How to create a user using ecto and phoenix v1.3
body: <p>I have a phoenix / phx v1.3 project that I have been working on, and have run into a issue trying to create a user using an <code>iex</code> session.  As far as I can tell the code that I have written should be working because the app compiles.</p>
  
  <p>I ran the below generator to setup a <code>schema</code> for user accounts.</p>
  
  <pre><code>mix phx.gen.json Accounts User users email:string encrypted_password:string username:string
  </code></pre>
  
  <p>I then followed through a couple of tutorials on how to setup the schema to accept the creation of user accounts by modifying,</p>
  
  <pre><code>/lib/kegcopr_api/accounts/user.ex
  </code></pre>
  
  <p><strong>user.ex</strong></p>
  
  <pre><code>defmodule KegCopRAPI.Accounts.User do
    use Ecto.Schema
    # import Ecto
    import Ecto.Changeset
    # import Ecto.Query
  
    schema "accounts_users" do
      field :email, :string
      field :encrypted_password, :string
      field :username, :string
      field :password, :string, virtual: true
  
      timestamps()
    end
  
    @required_fields ~w(email username)
    @optional_fields ~w()
  
    def changeset(struct, params \\ :empty) do
      struct
      |&gt; cast(params, @required_fields, @optional_fields)
      |&gt; validate_required(@required_fields, @optional_fields)
      # |&gt; cast(params, [:email, :encrypted_password, :username])
      # |&gt; validate_required([:email, :encrypted_password, :username])
      |&gt; validate_format(:email, ~r/@/)
      |&gt; validate_length(:username, min: 1, max: 20)
      |&gt; update_change(:email, &amp;String.downcase/1)
      |&gt; unique_constraint(:email)
      |&gt; update_change(:username, &amp;String.downcase/1)
      |&gt; unique_constraint(:username)
    end
  
    def registration_changeset(struct, params) do
      struct
      |&gt; changeset(params)
      |&gt; cast(params, ~w(password), [])
      |&gt; validate_required(~w(password), [])
      |&gt; validate_length(:password, min: 6, max: 100) |&gt; put_encrypted_pw
    end
  
    defp put_encrypted_pw(changeset) do
      case changeset do
        %Ecto.Changeset{valid?: true, changes: %{password: pass}} -&gt; put_change(changeset, :encrypted_password, Comeonin.Bcrypt.hashpwsalt(pass))
      _ -&gt;
        changeset
      end
    end
  end
  </code></pre>
  
  <p>I then run <code>iex -S mix</code> to start an interactive elixir session for the app, and I try to insert a user into the DB with the below command,</p>
  
  <pre><code>changeset = KegCopRAPI.Accounts.User.registration_changeset(%KegCopRAPI.Accounts.User{}, %{email: "first@example.com", username: "first", password: "password"})
  </code></pre>
  
  <p>However, the above mentioned command is giving me the below error,</p>
  
  <pre><code>warning: `Ecto.Changeset.cast/4` is deprecated, please use `cast/3` + `validate_required/3` instead
      (kegcopr_api) lib/kegcopr_api/accounts/user.ex:21: KegCopRAPI.Accounts.User.changeset/2
      (kegcopr_api) lib/kegcopr_api/accounts/user.ex:35: KegCopRAPI.Accounts.User.registration_changeset/2
      (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
      (stdlib) erl_eval.erl:438: :erl_eval.expr/5
      (elixir) src/elixir.erl:224: :elixir.erl_eval/3
      (elixir) src/elixir.erl:212: :elixir.eval_forms/4
      (iex) lib/iex/evaluator.ex:182: IEx.Evaluator.handle_eval/6
      (iex) lib/iex/evaluator.ex:175: IEx.Evaluator.do_eval/4
      (iex) lib/iex/evaluator.ex:155: IEx.Evaluator.eval/4
      (iex) lib/iex/evaluator.ex:61: IEx.Evaluator.loop/3
      (iex) lib/iex/evaluator.ex:21: IEx.Evaluator.init/4
      (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
  
  ** (ArgumentError) unknown field "email" for changeset on %KegCopRAPI.Accounts.User{__meta__: #Ecto.Schema.Metadata&lt;:built, "accounts_users"&gt;, email: nil, encrypted_password: nil, id: nil, inserted_at: nil, password: nil, updated_at: nil, username: nil}
             (ecto) lib/ecto/changeset.ex:1318: Ecto.Changeset.ensure_field_exists!/2
             (ecto) lib/ecto/changeset.ex:1305: anonymous fn/5 in Ecto.Changeset.validate_required/3
           (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
             (ecto) lib/ecto/changeset.ex:1304: Ecto.Changeset.validate_required/3
      (kegcopr_api) lib/kegcopr_api/accounts/user.ex:22: KegCopRAPI.Accounts.User.changeset/2
      (kegcopr_api) lib/kegcopr_api/accounts/user.ex:35: KegCopRAPI.Accounts.User.registration_changeset/2
  </code></pre>
  
  <p>Any help on how I can create a user would greatly be appreciated.  Presently, I'm not sure if the error is in the iex changeset command I am inputting or within the <code>user.ex</code> file.</p>