On page 103, we perform:
mix phx.gen.html Multimedia Video videos user_id:references:users \
url:string title:string description:text
The above code adds a field, user_id
, to the videos
tables.
video.ex:
defmodule Rumbl.Multimedia.Video do
use Ecto.Schema
import Ecto.Changeset
schema "videos" do
field :description, :string
field :title, :string
field :url, :string
field :user_id, :id
belongs_to :user, Rumbl.Accounts.User
belongs_to :category, Rumbl.Multimedia.Category
timestamps()
end
@doc false
def changeset(video, attrs) do
video
|> cast(attrs, [:url, :title, :description, :category_id])
|> validate_required([:url, :title, :description])
end
end
One page 121, when I attempt to perform:
mix ecto.gen.migration add_category_id_to_video
I’m getting the following error message:
Compiling 1 file (.ex)
== Compilation error in file lib/rumbl/multimedia/video.ex ==
** (ArgumentError) field/association :user_id is already set on schema
(ecto 3.5.8) lib/ecto/schema.ex:2056: Ecto.Schema.put_struct_field/3
(ecto 3.5.8) lib/ecto/schema.ex:1809: Ecto.Schema.define_field/4
(ecto 3.5.8) lib/ecto/schema.ex:1896: Ecto.Schema.__belongs_to__/4
lib/rumbl/multimedia/video.ex:11: (module)
(stdlib 3.14) erl_eval.erl:680: :erl_eval.do_apply/6
(elixir 1.11.3) lib/kernel/parallel_compiler.ex:314: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7