Phoenix框架:如何使用自定义端口运行ecto.create?

oka*_*kan 1 postgresql elixir phoenix-framework

如何在Phoenix 框架中为命令指定自定义服务器端口mix ecto.create

我使用命令创建了一个入门项目mix phx.new hellohello\config\dev.exs我在路径中配置数据库如下,

config :hello, Hello.Repo,
   username: "postgres",
   password: "postgres",
   hostname: "localhost",
   database: "hello_dev",
   show_sensitive_data_on_connection_error: true,
   pool_size: 10
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用该命令配置Postgres 数据库mix ecto.create时,出现以下错误。

** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
Run Code Online (Sandbox Code Playgroud)

我使用5433作为 Postgres 端口(注意:它适用于我的 spring java 项目),因为默认端口 5432 在我的本地不可用。

所以在hello\deps\ecto_sql\lib\ecto\adapters\postgres\connection.ex路径中我定义了路径中的默认端口,如下所示,

@default_port 5433
Run Code Online (Sandbox Code Playgroud)

但如果我再次运行该命令,它仍然尝试连接到 5432。

如何获取连接到 5433而不是 5432 的命令?

Dog*_*Dog 5

要在 Postgres 的自定义端口上运行 Ecto 迁移,请将 添加port: <port_number>,到配置中。连接的其他选项位于此处的 Ecto 文档中。因此,要将其设置为 port5433而不是默认 port 5432,您的配置将如下所示:

config :hello, Hello.Repo,
   username: "postgres",
   password: "postgres",
   hostname: "localhost",
   database: "hello_dev",
   port: 5433,
   show_sensitive_data_on_connection_error: true,
   pool_size: 10
Run Code Online (Sandbox Code Playgroud)