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

Phoenix framework: how to run ecto.create with custom port?

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

我使用 mix phx.new hello 命令创建了一个入门项目。 我在hello\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

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

** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

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

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

@default_port 5433

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

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

要在 Postgres 的自定义端口上 运行 Ecto 迁移,请将 port: <port_number>, 添加到配置中。连接的附加选项在 Ecto docs here 中。因此,要将其设置为端口 5433 而不是默认端口 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