适配器Ecto.Adapters.Postgres未编译

时间:2018-10-29 12:40:15

标签: postgresql elixir phoenix-framework ecto

我无法创建我的Phoenix项目。希望获得一些有关如何解决它的建议。

设置详细信息:

  • Ubuntu 16.04.4 LTS
  • Erlang / OTP 21 [erts-10.1] [源代码] [64位] [smp:1:1] [ds:1:1:10] [async-threads:1] [hipe]
  • Elixir 1.7.3(已编译 使用Erlang / OTP 20)
  • Mix 1.7.3(与Erlang / OTP 20编译)
  • Ecto v3.0.0

我正在按照Phoenix Up and Running制作应用。

mix phx.new hello
cd hello
mix ecto.create

最后一条命令给了我

 == 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

我已经安装了postgres。我有postgres超级用户。

4 个答案:

答案 0 :(得分:16)

从Ecto 3.0开始,Ecto默认不附带Ecto.Adapters.Postgres,因此必须将ecto_sql添加到Mixfile依赖项:

###########
# 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建议使用{:ecto_sql, "~> 3.0"},但最新版本为3.0.0-rc.1),因此目前无法使用。有趣的是,仓库中没有3.0.0-rc.1标签,但是the documentation已经引用了它,它也可以与mix一起使用。

...或者,如果您要启动新的Phoenix项目,则以Yufrend recommends in his answer的身份使用<1.4.0软件包。


请参阅何塞·瓦利姆(JoséValim)的“A sneak peek at Ecto 3.0” series,其中第一篇文章解释了Ecto 3.0的重大变化:

  

将Ecto拆分为ectoecto_sql

     

Ecto 3.0将分为两个存储库:ectoecto_sql。   自Ecto 2.0起,越来越多的开发人员和团队   使用Ecto进行数据映射和验证,无需   数据库。但是,将Ecto添加到您的应用程序仍会带来   很多SQL包,例如适配器,沙箱和迁移,   许多人认为这是混合消息。

     

在Ecto 3.0中,我们将所有SQL适配器移至单独的   存储库和Ecto将重点关注以下四个构建基块:模式,   变更集,查询和存储库。 You can see the discussion in the issues tracker.

     

如果您将Ecto与SQL数据库一起使用,则迁移到Ecto 3.0将   非常简单。代替:

{:ecto, "~> 2.2"}
     

您应该列出:

{:ecto_sql, "~> 3.0"}
     

如果您仅使用Ecto进行数据操作而没有使用   数据库访问,那么只需更改其版本即可。   就是这样!


更新

由于某些原因,我还需要在更新Phoenix 1.3项目时将{:plug_cowboy, "~> 1.0"}添加到Mixfile依赖项中,并且所有这些都开始工作。

答案 1 :(得分:7)

您的依赖项中是否有phoenix_ecto 3.5.0?在我弄清根本问题之前,降级到3.4.0对我来说是一个临时解决方案。

要强制降级:

  1. 运行mix deps.clean --all
  2. 删除您的mix.lock文件
  3. 更新限制mix.exs版本的phoenix_ecto文件。找到合适的行并替换为: {:phoenix_ecto, ">= 3.2.0 and < 3.5.0"},
  4. 运行mix deps.get

或者,如果您刚开始使用Phoenix,则可以使用1.4版进行学习,该版本将很快发布,并且没有此问题。

首先删除您当前的本地Phoenix存档:

mix archive.uninstall phx_new

然后,要安装最新的开发版本,请按照https://github.com/phoenixframework/phoenix/blob/master/installer/README.md

中的说明进行操作

答案 2 :(得分:2)

安装新的phoenix版本对我有用。

卸载旧版本:

mix archive.uninstall phx_new

安装新版本:

mix archive.install hex phx_new 1.4.0-rc.2

答案 3 :(得分:2)

新项目

要使用Ecto 3.0创建新项目,强烈建议您升级到新的phoenix 1.4.x安装程序:

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

现有项目

要将现有的Phoenix 1.3.x项目升级到1.4,请阅读Official Upgrade Guide和随附的announcement

TLDR是Ecto已细分为子包,您需要明确指定它们:

  

删除明显的:ecto依赖性,并使用以下版本更新:phoenix_ecto:ecto_sql依赖性:

        
{:ecto_sql, "~> 3.0-rc"},
{:phoenix_ecto, "~> 4.0"},