
conradwt
Programming Phoenix 1.4: Add category_id to video table (page 121)
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
Marked As Solved

conradwt
I was able to resolve the issue by removing user_id
field from the videos
schema. It would be great if the book was updated to show the error caused by having both
field :user_id, :id
and belongs_to :user, Rumbl.Accounts.User
and providing a resolution.
Popular Pragmatic Bookshelf topics

Hello Brian,
I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New

Title: Web Development with Clojure, Third Edition, pg 116
Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New

The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New

Dear Sophie.
I tried to do the “Authorization” exercise and have two questions:
When trying to plug in an email-service, I found the ...
New

“The ProductLive.Index template calls a helper function, live_component/3, that in turn calls on the modal component. ”
Excerpt From: Br...
New

I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New

In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
New

It seems the second code snippet is missing the code to set the current_user:
current_user: Accounts.get_user_by_session_token(session["...
New

Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New

I am using Android Studio Chipmunk | 2021.2.1 Patch 2
Build #AI-212.5712.43.2112.8815526, built on July 10, 2022
Runtime version: 11.0....
New
Other popular topics

@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness.
https://f...
New

I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New

No chair. I have a standing desk.
This post was split into a dedicated thread from our thread about chairs :slight_smile:
New

Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face:
https://on...
New

Do the test and post your score :nerd_face:
:keyboard:
If possible, please add info such as the keyboard you’re using, the layout (Qw...
New

Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New

This is going to be a long an frequently posted thread.
While talking to a friend of mine who has taken data structure and algorithm cou...
New

Author Spotlight
James Stanier
@jstanier
James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New

Author Spotlight
Dmitry Zinoviev
@aqsaqal
Today we’re putting our spotlight on Dmitry Zinoviev, author of Data Science Essentials in ...
New

Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /onivim
- /typescript
- /svelte
- /crystal
- /kotlin
- /c-plus-plus
- /tailwind
- /react
- /gleam
- /ocaml
- /elm
- /flutter
- /vscode
- /ash
- /html
- /opensuse
- /centos
- /php
- /deepseek
- /zig
- /scala
- /sublime-text
- /textmate
- /lisp
- /nixos
- /debian
- /react-native
- /agda
- /kubuntu
- /arch-linux
- /django
- /revery
- /ubuntu
- /manjaro
- /spring
- /nodejs
- /diversity
- /lua
- /julia
- /c
- /slackware
- /markdown