Ecto adapter error

Hello.

I’m having a strange problem.
I started an application with Ecto, but I keep getting this error:

== Compilation error on file lib/cards.ex ==
** (ArgumentError) missing :adapter configuration in config :cards, Cards.Repo
    lib/ecto/repo/supervisor.ex:37: Ecto.Repo.Supervisor.parse_config/2
    lib/cards.ex:16: (module)
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6

In my config file, I have this:

use Mix.Config

config :cards, ecto_repos: [Cards.Repo]

config :cards, Cards.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "ffff00123123",
  database: "cards_repository_dev",
  hostname: "localhost",
  pool_size: 10

In my mix.exs file, I have this:

defmodule Cards.Mixfile do
  use Mix.Project

  def project do
    [app: :cards,
     version: "0.0.1",
     build_path: "../../_build",
     config_path: "../../config/config.exs",
     deps_path: "../../deps",
     lockfile: "../../mix.lock",
     elixir: "~> 1.2",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     aliases: aliases,
     deps: deps]
  end

  def application do
    [mod: {Cards, []},
     applications: [:logger, :postgrex, :ecto]]
  end

  defp deps do
    [{:postgrex, "~> 0.11"},
     {:ecto, ">= 0.0.0"}]
  end

  defp aliases do
    ["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
     "ecto.reset": ["ecto.drop", "ecto.setup"]]
  end
end

And in my cards module, I have this:

defmodule Cards do
  use Application

  def start(_one, _two) do
    import Supervisor.Spec, warn: false

    children = [
      worker(Cards.Repo, [])
    ]

    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

defmodule Cards.Repo do
  use Ecto.Repo, otp_app: :cards
end

I can’t get it to work! Why is that? :confounded:

Edit: the worst part is that this applications is in a umbrella app, and it works OK in one of the apps as an umbrella dependency, but it doesn’t work on another app. Why? I can’t see why.

The only difference I spotted is that in the apps that work, a mix.lock is available. How, on Earth, can the same application compile as a umbrella dependency in one app and it won’t compile on another app? How?

I can’t really see anything wrong honestly. The only minor mistake I see is that worker(Cards.Repo, []) should be supervisor(Cards.Repo, []) but I doubt that is your problem…

Do you have a git repo for us to try it locally?

2 Likes

I would make sure the config is loaded. Is the config in the proper environment? Is the environment file imported at the end of main config.exs? Is there maybe something overriding the config?

You can also inspect the actual config that ends up being loaded at the beginning of your application’s start callback using Application.get_env(:cards, Cards.Repo) and check if it gives you what you’d expect.

1 Like

I’ve changed worker to supervisor but no avail ):

I’ll drop a git repo for you guys to see it in a few minutes.

I thought about that, but the problem is that the application isn’t even started. It fails at compile time.
The config, AFAIK, is OK. I’ll upload a git repo and paste it here in a few minutes.

@nubunto I couldn’t compile the test repo, because of this error: (Mix.Config.LoadError) could not load config ../../config/config.exs - indeed there’s something wrong with your config.

Looking at your mix.exs, it seems that you originally had your app as an umbrella project, because apps within umbrella projects are modifying paths, e.g. here: https://github.com/nubunto/ecto_repo_test/blob/master/mix.exs#L8. You can remove your overrides for build_path, config_path, deps_path, lockfile and it should work - it compiled for me.

1 Like

You da real mvp @wojtekmach, thank you very very much!

So the lesson learned today was: When you’re using umbrella apps, those freakin’ paths play a important part in making your app build properly.

1 Like

Ok, but now the problem is that in the phoenix app that uses cards as an umbrella dependency, I still get the same error.

WTF?

Edit: I need to import the config from the cards app into my Phoenix app. That solved it.

Solved my problem too, thanks!

1 Like