Owens

Owens

How to read Postgrex SQL ERROR 42703

Hello all,

I’m scratching my head trying to read this error log from Postgrex.

** (Postgrex.Error) ERROR 42703 (undefined_column) column c2.user_id does not exist

    query: SELECT t0."id", t0."logo_url", t0."icon_url", t0."invite_password",
t0."is_company", t0."long_description", t0."name", t0."short_description",
t0."company_id", t0."inserted_at", t0."updated_at",
c1."id" FROM "teams" AS t0 INNER JOIN "cohorts"
AS c1 ON c1."id" = ANY($1) INNER JOIN  "cohorts_teams"
AS c2 ON c2."cohort_id" = c1."id" WHERE (c2."user_id" = t0."id") ORDER BY c1."id"

Here’s the function call.

teams_query = Team |> preload(:teams_users)
organization_query = Organization |> preload(:organizations_users)

cohort = Cohort
|> preload([teams: ^teams_query, organization: ^organization_query])
|> Repo.get!(cohort_id)

It appears to be looking for user_id on the cohorts_teams table, which doesn’t exist. If so, why could it be looking for this?

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

You have a mistake here: many_to_many :teams, Rocketship.Accounts.User, join_through: "cohorts_teams". This should be Rocketship.Accounts.Team probably.

Also, if you use join_through and then a string it won’t use the schema, you need to join_through: [:cohorts_teams, :team]

Also Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

As a first note, the stuff you’re linking to are quite old, Ecto 3.X has been out for a while.

Secondly, I was a bit wrong now that I looked at it, I got join_through: confused with has_many through Ecto.Schema — Ecto v3.14.0. I almost always use an actual schema in the middle and not many_to_many.

Where Next?

Popular in Questions Top

electic
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
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
9mm
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
pmjoe
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
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement