When MIX_ENV=test mix ecto.create will not create the test database specified in test.exs

For some unknown to me reason, my project only wants to use my dev database for testing. It refuses to create the test database and will run the tests using the dev database and I have no idea why.

When I run MIX_ENV=test mix ecto.create it tells me that the database has already been created The database for MyProject.Repo has already been created

Any ideas on why this might happen?

1 Like

Can you provide your config.exs, test.exs and confirm whether or not you have a runtime.exs set in your config directory? If there’s sensitive information in those files, just redact them and should be enough to figure it out.

When you run your tests with mix test, it actually runs the alias which typically looks like this:

test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],

It mostly likely has created your *_test database for you as well. Probably best to check using a database viewer to confirm that this is the case.


I figured it out. It was because an env variable overrides the normal config in test.exs, so with that variable set it was using the wrong database name. I cleared that env and voila, it is working now.