Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 尝试实现时出错";geo";postgrex延伸型_Postgresql_Ecto_Elixir_Postgrex - Fatal编程技术网

Postgresql 尝试实现时出错";geo";postgrex延伸型

Postgresql 尝试实现时出错";geo";postgrex延伸型,postgresql,ecto,elixir,postgrex,Postgresql,Ecto,Elixir,Postgrex,下面是一个将postgrex扩展添加到config.exs中的extensions字段。然而,现在添加postgrex扩展名的方法已被弃用,我们现在应该使用type字段,而不是extensions字段。我按照上的代码添加扩展名: config.exs Postgrex.Types.define(MyApp.PostgresTypes, [Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(), json: Poison)

下面是一个将postgrex扩展添加到
config.exs
中的
extensions
字段。然而,现在添加postgrex扩展名的方法已被弃用,我们现在应该使用
type
字段,而不是
extensions
字段。我按照上的代码添加扩展名:

config.exs

Postgrex.Types.define(MyApp.PostgresTypes,
  [Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
  json: Poison)

use Mix.Config

config :api, Api.Repo,
  types: MyApp.PostgresTypes,
  adapter: Ecto.Adapters.Postgres,
  database: "api_repo",
  username: "postgres",
  password: "postgres",
  hostname: "localhost",
  web_port: String.to_integer(System.get_env("PORT") || "4000"),
  timeout: 60_000,
  pool_timeout: 60_000

config :api, ecto_repos: [Api.Repo]
但我得到了一个错误:

bash-3.2$ mix ecto.migrate
** (Mix.Config.LoadError) could not load config config/config.exs
    ** (UndefinedFunctionError) function Ecto.Adapters.Postgres.extensions/0 is undefined (module Ecto.Adapt
ers.Postgres is not available)
    Ecto.Adapters.Postgres.extensions()
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (stdlib) erl_eval.erl:470: :erl_eval.expr/5
    (stdlib) erl_eval.erl:878: :erl_eval.expr_list/6
    (stdlib) erl_eval.erl:404: :erl_eval.expr/5
    (stdlib) erl_eval.erl:122: :erl_eval.exprs/5

我在网上看到,这有时是由于一个非常旧的版本,我正在使用
{:postgrex,~>0.13.2},
。我缺少什么?

定义自定义Postgrex类型的行需要放在一个
.ex
文件中,该文件是用你的应用程序编译的(在
lib/
web/
中的任何内容),而不是配置文件中。配置文件无权访问应用程序的依赖项功能

因此,如果将此代码移动到例如
lib/my\u app/postgres\u types.ex

Postgrex.Types.define(MyApp.PostgresTypes,
  [Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
  json: Poison)

你不应该再出现未定义的函数错误,如果你正确地遵循了
geo
包中的其余说明,那么一切都应该正常工作。

你下载并安装了PostGIS吗?@a_horse_,没有名字啊,没有。我只是在我的dep中安装了geo:
[{:geo,~>1.4}]
。我会下载你使用的是哪个版本的Ecto?(请参见mix.lock中的确切版本)@Dogbert-exto版本2.1.4