Use build association between schemas
<p>I have following schemas:</p>

<p>The first:</p>

<pre><code>schema "countries_codes" do

    # Country code based on ISO-2
    field :iso,        :string
    field :name,       :string
    has_many :country, Country

    timestamps

  end

  def changeset(struct, params \\ %{}) do

    struct
    |&gt; cast(params, [:iso, :name])
    |&gt; validate_required([:iso, :name])
    |&gt; validate_length(:iso, max: 2)

  end
</code></pre>

<p>the second: </p>

<pre><code>schema "languages_codes" do

    # Language code based on ISO-2
    field :iso,        :string
    field :name,       :string
    has_many :country, Country

    timestamps

  end

  def changeset(struct, params \\ %{}) do

    struct
    |&gt; cast(params, [:iso, :name])
    |&gt; validate_required([:iso, :name])
    |&gt; validate_length(:iso, max: 2)

  end
</code></pre>

<p>and the third:</p>

<pre><code>schema "countries" do

    belongs_to :country_iso,  CountryCode
    belongs_to :language_iso, LanguageCode
    field :name,              :string

    timestamps

  end

  def changeset(struct, params \\ %{}) do

    struct
    |&gt; cast(params, [:country_iso, :language_iso, :name])
    |&gt; cast_assoc(:country_iso)
    |&gt; validate_required([:country_iso, :language_iso, :name])

  end
</code></pre>

<p>as you can see on the third table, the first and second field belong to other schema. </p>

<p>When I run the <code>country</code> changeset function, I've got:</p>

<pre><code>** (RuntimeError) casting assocs with cast/3 is not supported, use cast_assoc/3 instead
    (ecto) lib/ecto/changeset.ex:440: Ecto.Changeset.type!/2
    (ecto) lib/ecto/changeset.ex:415: Ecto.Changeset.process_param/8
    (elixir) lib/enum.ex:1247: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (ecto) lib/ecto/changeset.ex:391: Ecto.Changeset.do_cast/7
    (busiket) web/models/country.ex:20: Busiket.Country.changeset/2
    (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
    priv/repo/seeds.exs:48: (file)
    (elixir) lib/code.ex:363: Code.require_file/2
    (mix) lib/mix/tasks/run.ex:71: Mix.Tasks.Run.run/1
    (mix) lib/mix/task.ex:296: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2
    (elixir) lib/code.ex:363: Code.require_file/2
</code></pre>

<p>My problem is, I do not know, how to write a changeset function for the schema <code>countries</code>.</p>