Reputation: 507
I am not able to create my Phoenix project. Would love some advice on how to fix it.
Setup details:
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.
Upvotes: 27
Views: 5908
Reputation: 75760
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
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"},
Upvotes: 2
Reputation: 8273
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
andecto_sql
Ecto 3.0 will be broken in two repositories:
ecto
andecto_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.
Upvotes: 29
Reputation: 123
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
Upvotes: 2
Reputation: 148
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:
mix deps.clean --all
mix.lock
filemix.exs
file limiting the phoenix_ecto
version. Find the appropriate line and replace with:
{:phoenix_ecto, ">= 3.2.0 and < 3.5.0"},
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
Upvotes: 8