Twfo326

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

Showing Posts 1 to 2

benwilson512

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.

Twfo326

Twfo326 OP

Thanks for the solution and debugging tips.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews