Reputation:
I'm trying to add Ecto to my project. It's a standard project not generated with --s
to add a supervisor.
So far I've used
mix ecto.gen.repo -r MyApp.Repo
Which generates it just fine.
In my config/dev.exs
I have the following:
config :my_app,
ecto_repos: [MyApp.Repo]
config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
database: System.get_env("DATABASE_NAME"),
username: System.get_env("DATABASE_USER"),
password: System.get_env("DATABASE_PASSWORD"),
hostname: System.get_env("DATABASE_HOST"),
port: System.get_env("DATABASE_PORT")
In myapp/repo.ex
I have:
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
end
However, when I go to create the repo with
mix ecto.create --env=dev
I get
warning: could not find Ecto repos in any of the apps: [:my_app].
You can avoid this warning by passing the -r flag or by setting the
repositories managed by those applications in your config/config.exs:
config :eos, ecto_repos: [...]
This also occurs if I omit the --env
flag.
I am hopelessly lost. This is consistent with the getting started guide (minus the supervisor stuff which it did not indicate was required), and I'm stalled out here. Can anyone help me sort this out? Thank you!
Upvotes: 1
Views: 2212
Reputation: 222398
Elixir only loads the config declarations in config/config.exs
by default. The <env>.exs
convention used by many projects including Phoenix requires the following line to be added to the end of config/config.exs
in order to load the correct exs file:
import_config "#{Mix.env}.exs"
Upvotes: 1