adapter Ecto.Adapters.Postgres was not compiled
Asked Answered
R

4

27

I am not able to create my Phoenix project. Would love some advice on how to fix it.

Setup details:

  • Ubuntu 16.04.4 LTS
  • Erlang/OTP 21 [erts-10.1] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]
  • Elixir 1.7.3 (compiled with Erlang/OTP 20)
  • Mix 1.7.3 (compiled with Erlang/OTP 20)
  • Ecto v3.0.0

I am following the Phoenix Up and Running to make an app.

mix phx.new hello
cd hello
mix ecto.create

last command gives me:

 == Compilation error in file lib/hello/repo.ex ==
 ** (ArgumentError) adapter Ecto.Adapters.Postgres was not compiled, ensure it is correct and it is included as a project dependency
     lib/ecto/repo/supervisor.ex:71: Ecto.Repo.Supervisor.compile_config/2
     lib/hello/repo.ex:2: (module)
     (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
     (elixir) lib/kernel/parallel_compiler.ex:206: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

I have postgres installed. I have postgres super user.

Riff answered 29/10, 2018 at 12:40 Comment(3)
In your projects mix.exs file. Do you have something like {:postgrex, ">= 0.0.0"} in your dependencies?Weather
yes, I changed to {:postgrex, ">= 0.10.0"} after reading in some blogs, but no luck :(Riff
Did you include ecto_sql as a dependency?Weather
B
8

Do you have phoenix_ecto 3.5.0 in your dependencies? Downgrading to 3.4.0 worked for me as a temporary fix until I figure out the underlying issue.

To force a downgrade:

  1. Run mix deps.clean --all
  2. Delete your mix.lock file
  3. Update your mix.exs file limiting the phoenix_ecto version. Find the appropriate line and replace with: {:phoenix_ecto, ">= 3.2.0 and < 3.5.0"},
  4. Run mix deps.get

Alternatively, if you are just starting with Phoenix, you could use version 1.4 to learn, which will be released soon and does not have this issue.

First remove your current local Phoenix archive:

mix archive.uninstall phx_new

Then, to install the latest development version, follow the instructions in https://github.com/phoenixframework/phoenix/blob/master/installer/README.md

Berkshire answered 29/10, 2018 at 13:41 Comment(1)
Decided to go for the uninstall and instal new RC method as I am just starting out. ThanksRiff
M
29

Starting with Ecto 3.0, Ecto.Adapters.Postgres is not shipped with Ecto by default, therefore you have to add ecto_sql to the Mixfile dependencies:

###########
# mix.exs #
###########
defp deps do
  [
    # (...)
    {:ecto_sql, "~> 3.0-rc.1"},
    {:postgrex, ">= 0.0.0"}
  ]
end

# Feeling skittish about dependencies, 
# I usually do this instead of simply 
# doing `mix deps.get`:

$ mix deps.clean --all
$ mix do deps.get, compile

(The Ecto github repo v3.0.0 tree recommends {:ecto_sql, "~> 3.0"}, but the latest release is the 3.0.0-rc.1) therefore it won't work as of now. Interestingly there is no 3.0.0-rc.1 tag in the repo, but the documentation already refers to that and it also works with mix.)

...or, as Yufrend recommends in his answer, if you are starting a new Phoenix project, use < 1.4.0 packages.


See José Valim's “A sneak peek at Ecto 3.0” series where the first post explains the breaking changes in Ecto 3.0:

Split Ecto into ecto and ecto_sql

Ecto 3.0 will be broken in two repositories: ecto and ecto_sql. Since Ecto 2.0, an increased number of developers and teams have been using Ecto for data mapping and validation, without a need for a database. However, adding Ecto to your application would still bring a lot of the SQL baggage, such as adapters, sandboxes and migrations, which many considered to be a mixed message.

In Ecto 3.0, we will move all of the SQL adapters to a separate repository and Ecto will focus on the four building blocks: schemas, changesets, queries and repos. You can see the discussion in the issues tracker.

If you are using Ecto with a SQL database, migrating to Ecto 3.0 will be very straight-forward. Instead of:

{:ecto, "~> 2.2"}

You should list:

{:ecto_sql, "~> 3.0"}

And if you are using Ecto only for data manipulation but with no database access, then it is just a matter of bumping its version. That’s it!


UPDATE

For some reason, I also needed to add {:plug_cowboy, "~> 1.0"} to the Mixfile dependencies when updating a Phoenix 1.3 project and it all started working.

Molluscoid answered 30/10, 2018 at 5:15 Comment(0)
B
8

Do you have phoenix_ecto 3.5.0 in your dependencies? Downgrading to 3.4.0 worked for me as a temporary fix until I figure out the underlying issue.

To force a downgrade:

  1. Run mix deps.clean --all
  2. Delete your mix.lock file
  3. Update your mix.exs file limiting the phoenix_ecto version. Find the appropriate line and replace with: {:phoenix_ecto, ">= 3.2.0 and < 3.5.0"},
  4. Run mix deps.get

Alternatively, if you are just starting with Phoenix, you could use version 1.4 to learn, which will be released soon and does not have this issue.

First remove your current local Phoenix archive:

mix archive.uninstall phx_new

Then, to install the latest development version, follow the instructions in https://github.com/phoenixframework/phoenix/blob/master/installer/README.md

Berkshire answered 29/10, 2018 at 13:41 Comment(1)
Decided to go for the uninstall and instal new RC method as I am just starting out. ThanksRiff
A
2

Installing the new phoenix version worked for me.

Uninstall old version:

mix archive.uninstall phx_new

Install new version:

mix archive.install hex phx_new 1.4.0-rc.2

Aurie answered 30/10, 2018 at 11:58 Comment(0)
K
2

New Projects

For creating new projects with Ecto 3.0, it's highly recommended you upgrade to the new phoenix 1.4.x installer:

$ mix archive.uninstall phx_new
$ mix archive.install hex phx_new 1.4.0-rc.2

Existing Projects

To upgrade your existing Phoenix 1.3.x projects to 1.4, read the Official Upgrade Guide and the accompanying announcement.

TLDR is that Ecto has been broken into sub-packages, and you need to specify them explicitly:

Remove your explicit :ecto dependency and update your :phoenix_ecto and :ecto_sql dependencies with the following versions:

{:ecto_sql, "~> 3.0-rc"},
{:phoenix_ecto, "~> 4.0"},
Kershner answered 30/10, 2018 at 18:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.