Ecto Testing Setup Env

Hi all! Trying to get a project setup for testing with my functioning Ecto database by following the docs . Running into an issue-

I keep getting an error upon compiling-

** (File.Error) could not read file "/photo_grid/config/dev.exs": no such file or directory

I know that this is related to the bottom import_config line in config.exs, right?

config/config.exs

import Config

config :photo_grid, Posts.Repo,
  database: "photo_grid_repo",
  username: "postgres",
  password: "pass",
  hostname: "localhost"


config :photo_grid, ecto_repos: [Posts.Repo]

import_config "#{Mix.env()}.exs"

From the docs, it’s just looking for this test.exs file also located under the config directory right?

config/test.exs

use Mix.Config

config :photo_grid, PhotoGrid.Repo,
  username: "postgres",
  password: "postgres",
  database: "photo_grid_test",
  hostname: "localhost",
  pool: Ecto.Adapters.SQL.Sandbox

I’m not sure how to set this correctly or what I’m missing. Thanks for any help :slight_smile:

Is it asking me to just create a file - config/dev.exs? I did that with duplicate settings as config.exs and that fixed the issue, but not sure if that’s correct.

You should not skip the basics: Config — Elixir v1.14.0

But in all fairness, depending on your needs, you could probably do without env-specific config. Though I still prefer using it because the alternatives don’t work well for all kinds of projects.

1 Like

That’s totally fair Dimitar! I need to do more reading on the specifics for Config. Thanks :smile: