1

按照标准程序创建一个新的 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
4

1 回答 1

2

必须为配置数据库。确保你有类似下面几行的内容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 中的密码设置为空。

于 2021-10-13T11:41:35.573 回答