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

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
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
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
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
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

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
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
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
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement