Twfo326
Postgrex Error 42P01 relation "characters" does not exist
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
Marked As Solved
benwilson512
Author of Craft GraphQL APIs in Elixir with Absinthe
It looks like you have a typo here. This says “charaters” but should be “characters”.
In the future, you can also psql your_database_here and then type \l to have it list the tables that exist, which can help make it easier to see typos like this.
3
Last Post!
Twfo326
Popular in Questions
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









