Twfo326
I’m running into this error
** (Postgrex.Error) ERROR 42P01 (undefined_table) relation "characters" does not exist
when I try to insert a character into the DB.
Steps taken:
Creating a movie:
alias Friends.{Movie, Character, Repo}
movie = %Movie{title: "Ready Player One", tagline: "Something about video games"}
Inserting the movie:
movie = Repo.insert!(movie)
Creating a character
character = Ecto.build_assoc(movie, :characters, %{name: "Wade Watts"})
Inserting a character
Repo.insert!(character)
18:03:52.358 [debug] QUERY ERROR db=0.0ms queue=5.5ms idle=1209.5ms
INSERT INTO "characters" ("movie_id","name") VALUES ($1,$2) RETURNING "id" [1, "Bruce"]
** (Postgrex.Error) ERROR 42P01 (undefined_table) relation "characters" does not exist
query: INSERT INTO "characters" ("movie_id","name") VALUES ($1,$2) RETURNING "id"
(ecto_sql 3.7.2) lib/ecto/adapters/sql.ex:760: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto 3.7.2) lib/ecto/repo/schema.ex:744: Ecto.Repo.Schema.apply/4
(ecto 3.7.2) lib/ecto/repo/schema.ex:367: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
(ecto 3.7.2) lib/ecto/repo/schema.ex:269: Ecto.Repo.Schema.insert!/4
Output from:
mix do ecto.drop, ecto.create, ecto.migrate
The database for Friends.Repo has been dropped
The database for Friends.Repo has been created
17:59:56.273 [info] == Running 20220316202504 Friends.Repo.Migrations.CreatePeople.change/0 forward
17:59:56.278 [info] create table people
17:59:56.297 [info] == Migrated 20220316202504 in 0.0s
17:59:56.342 [info] == Running 20220316223207 Friends.Repo.Migrations.CreateMovies.change/0 forward
17:59:56.342 [info] create table movies
17:59:56.356 [info] == Migrated 20220316223207 in 0.0s
17:59:56.364 [info] == Running 20220316224808 Friends.Repo.Migrations.CreateCharacters.change/0 forward
17:59:56.364 [info] create table charaters
17:59:56.372 [info] == Migrated 20220316224808 in 0.0s
17:59:56.380 [info] == Running 20220317003543 Friends.Repo.Migrations.CreateDistributors.change/0 forward
17:59:56.380 [info] create table distributors
17:59:56.388 [info] create index distributors_movie_id_index
17:59:56.394 [info] == Migrated 20220317003543 in 0.0s
17:59:56.402 [info] == Running 20220318020506 Friends.Repo.Migrations.CreateActors.change/0 forward
17:59:56.402 [info] create table actors
17:59:56.414 [info] == Migrated 20220318020506 in 0.0s
17:59:56.421 [info] == Running 20220318020901 Friends.Repo.Migrations.CreateMoviesActors.change/0 forward
17:59:56.421 [info] create table movies_actors
17:59:56.429 [info] create index movies_actors_movie_id_actor_id_index
17:59:56.435 [info] == Migrated 20220318020901 in 0.0s
movie schema:
defmodule Friends.Movie do
use Ecto.Schema
schema "movies" do
field(:title, :string)
field(:tagline, :string)
has_many(:characters, Friends.Character)
has_one(:distributor, Friends.Distributor)
many_to_many(:actors, Friends.Actor, join_through: "movies_actors")
end
end
character schema`
defmodule Friends.Character do
use Ecto.Schema
schema "characters" do
field(:name, :string)
belongs_to(:movie, Friends.Movie)
end
end
*The project is from the Ecto Elixir School tutorial
https://elixirschool.com/en/lessons/ecto/associations
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
benwilson512
It looks like you have a typo here. This says “charaters” but should be “characters”.
In the future, you can also
psql your_database_hereand then type\lto have it list the tables that exist, which can help make it easier to see typos like this.Twfo326
Thanks for the solution and debugging tips.