AarKiMos

AarKiMos

(RuntimeError) could not lookup Ecto repo MyApp.Repo because it was not started or it does not exist

Trying to call any Repo functions in any of the controllers would result in this error, wouldn’t even compile, compile successes if I comment any such calls.

== Compilation error in file lib/my_app_web/controllers/contact_controller.ex ==
** (RuntimeError) could not lookup Ecto repo MyApp.Repo because it was not started or it does not exist
    (ecto 3.9.4) lib/ecto/repo/registry.ex:22: Ecto.Repo.Registry.lookup/1
    (ecto 3.9.4) lib/ecto/repo/supervisor.ex:160: Ecto.Repo.Supervisor.tuplet/2
    lib/my_app/repo.ex:2: Vitalx.Repo.all/2
    lib/my_app_web/controllers/contact_controller.ex:11: (module)

Was working fine few minutes ago, all of a sudden this happens. Please advice on how to troubleshoot this.

Marked As Solved

AarKiMos

AarKiMos

Hi, I got it solved, will make sure to include code from next time.

I wonder if you are making a Repo call within the module body that’s being executed at compile time.

Was doing exactly this, was creating a module attribute with data fetched from database. Somehow ended up trying multiple calls from multiple contexts in multiple controllers all using module attributes only and getting the same error trying to troubleshoot this.

Made it into a private function :smiley:

----------- Errornous code

@contact_query_recipients Email.list_contact_query_subscribers()
                           |> Enum.map(fn s -> {s.name, s.email} end)

----------- Fixed code

  defp list_recipients do
    Email.list_contact_query_subscribers()
    |> Enum.map(fn s -> {s.name, s.email} end)
  end

Also Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @AarKiMos welcome! Any time you have an error it will help a lot if you can post the code you have. Can you show the full controller module? I wonder if you are making a Repo call within the module body that’s being executed at compile time.

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
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
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement