Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adapter Ecto.Adapters.Postgres was not compiled

Tags:

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.

like image 846
Devatanu Avatar asked Oct 29 '18 12:10

Devatanu


1 Answers

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.

like image 131
toraritte Avatar answered Sep 21 '22 15:09

toraritte