【问题标题】:Encounter error when creating a new Phoenix/Elixir project创建新的 Phoenix/Elixir 项目时遇到错误
【发布时间】:2021-12-01 20:48:51
【问题描述】:

按照标准程序创建一个新的 Phoenix/Elixir 项目。但是,在安装过程中遇到错误。请评论如何解决此错误。

0。设置

$ node -v
v14.18.1

$ npm -v
6.14.15

$ elixir -v
Erlang/OTP 24 [erts-12.1.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit] [dtrace]
Elixir 1.12.3 (compiled with Erlang/OTP 24)

$ mix phx.new --version
Phoenix installer v1.6.2

1.创建一个文件夹来保存数据库数据。

mkdir ${HOME}/phoenix-postgres-data/

2。使用 Postgres 映像运行 Docker 容器。

$ docker run -d \
 --name phoenix-psql \
 -e POSTGRES_PASSWORD=Phoenix1234 \
 -v ${HOME}/phoenix-postgres-data/:/var/lib/postgresql/data \
 -p 5432:5432 \
 postgres

3.验证容器是否正在运行。

$ docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED       STATUS         PORTS                                       NAMES
fca9fbc140e6   postgres   "docker-entrypoint.s…"   4 hours ago   Up 6 minutes   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   phoenix-psql

4.创建新项目

$ mix phx.new pento --live
* creating pento/config/config.exs
* creating pento/config/dev.exs
* creating pento/config/prod.exs
* creating pento/config/runtime.exs
...
* creating pento/priv/static/favicon.ico

Fetch and install dependencies? [Yn] Y
* running mix deps.get
* running mix deps.compile

5.画龙点睛

$ cd pento
$ mix ecto.create && mix phx.server && iex -S mix phx.server

错误信息

Compiling 14 files (.ex)
Generated pento app

18:47:31.378 [error] GenServer #PID<0.411.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
    (db_connection 2.4.0) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.16.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

18:47:31.423 [error] GenServer #PID<0.419.0> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
    (db_connection 2.4.0) lib/db_connection/connection.ex:100: DBConnection.Connection.connect/2
    (connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.16.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for Pento.Repo couldn't be created: killed

【问题讨论】:

  • 您是否使用正确的数据库凭据更新了config/dev.exs(和其他人?)?您是否能够独立登录数据库,例如使用 psql CLI 或 PSequel?

标签: elixir ecto phoenix phoenix-live-view


【解决方案1】:

必须为 配置数据库。确保您的 config/config.exs 中有类似以下行的内容

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "postgres",
  password: "Phoenix1234",
  database: "my_app_dev",
  hostname: "localhost",
  pool_size: 10

或者。或者,将 docker postgres 中的密码设置为空。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 2017-10-21
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多