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
Hi, I got it solved, will make sure to include code from next time.
I wonder if you are making a
Repocall 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 ![]()
----------- 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
Popular in Questions
Other popular topics
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
- #forms
- #api
- #metaprogramming
- #security
- #hex









