gpt4 book ai didi

postgresql - 适配器 Ecto.Adapters.Postgres 未编译

转载 作者:行者123 更新时间:2023-11-29 11:08:54 25 4
gpt4 key购买 nike

我无法创建 Phoenix 项目。想要一些关于如何修复它的建议。

设置细节:

  • Ubuntu 16.04.4 LTS
  • Erlang/OTP 21 [erts-10.1] [源代码] [64 位][smp:1:1] [ds:1:1:10] [异步线程: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 super 用户。

最佳答案

从 Ecto 3.0 开始,默认情况下 Ecto.Adapters.Postgres 不随 Ecto 一起提供,因此您必须将 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)因此它现在不起作用。有趣的是, repo 中没有 3.0.0-rc.1 标签,但是 the documentation已经提到了它,它也适用于 mix)

...或者,作为 Yufrend recommends in his answer ,如果您要开始一个新的 Phoenix 项目,请使用 < 1.4.0 包。


参见 José Valim 的 “A sneak peek at Ecto 3.0” series第一篇文章解释了 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!


更新

出于某种原因,我还需要在更新 Phoenix 1.3 项目时将 {:plug_cowboy, "~> 1.0"} 添加到 Mixfile 依赖项中,一切都开始工作了。

关于postgresql - 适配器 Ecto.Adapters.Postgres 未编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53045717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com