How to make a simple Ecto app a dependency in a simple Elixir app?

Just finished the Ecto tutorial and building the friends example app. Everything works as expected in a iex CRUD session.
Now, I want to make that friends app I just built a dependency in a simple Elixir app. I don’t want to wrestle just yet with an umbrella app or a phoenix app, but just a straightforward Elixir app with the friends app as a dependency.

So I created a: $ mix new test_app --sup, added the friends app as a dependency by referencing its repo location, and ran $ mix deps.get.
Next from the test_app directory I stepped into the deps/friends directory and ran the usual sequence of mix ecto commands (drop, create, migrate) to prep the dependency.

However, after all that when I then run from the parent test_app directory $ mix compile I get the following error:

== Compilation error in file lib/friends/repo.ex ==
** (ArgumentError) missing :adapter configuration in config :friends, Friends.Repo
lib/ecto/repo/supervisor.ex:69: Ecto.Repo.Supervisor.compile_config/2
lib/friends/repo.ex:2: (module)
(stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
could not compile dependency :friends, “mix compile” failed. You can recompile this dependency with “mix deps.compile friends”, update it with “mix deps.update friends” or clean it with “mix deps.clean friends”

Is there something Ecto related I must do in the parent test_app so its mix can figure how to work with the friends dependency?


Judging by the error, you need to set :adapter in your friends app’s config.

Yea, you’d think so by way of the error message, but the friend app as a standalone app works fine (wouldn’t if the :adapter line wasn’t there), but I double checked anyway - the :adapter line in config is there. Headscratcher…

I’m looking around for an existing example of what I’m trying to accomplish to grok what configuration between the two apps I need to do…

Well, cruising through the various boards it appears “you can’t get there from here” with this approach. Looks like I need to apply the Umbrella construct if I want an Ecto app as a dependency to another app.

You need to have the config values for the dependency (friends) app in the config of your actual app. Elixir takes the config values for the dependency app from the parent app that’s running.

In your test_app config have this:


 # Configure your database
config :friends, Friends.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "postgres",
  database: "friends_dev",
  pool_size: 10

Thanks praveen,

That worked. The coupling is unfortunate, but it works.


Thanks praveen,

That worked. The coupling is unfortunate, but that worked.


1 Like

Thanks Praveen! Saved my day, my independent app is no longer refusing connection …

1 Like