【发布时间】:2021-01-01 03:33:35
【问题描述】:
我创建了一个新的 Phoenix 项目并检查了 config/dev.exs 中的凭据,它们是:
config :blog, Blog.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "blog_dev",
hostname: "localhost",
pool_size: 10
现在,数据库blog_dev 不存在,但我的(总体初学者级别)理解mix ecto.create 应该在它不存在的情况下创建它。于是我跑了:
mix ecto.create
这给了我错误
localhost:blog alex$ mix ecto.create
warning: found quoted keyword "test" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes
mix.exs:57
18:04:24.675 [error] GenServer #PID<0.212.0> terminating
** (DBConnection.ConnectionError) tcp recv: closed
(db_connection) lib/db_connection/connection.ex:163: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for Blog.Repo couldn't be created: an exception was raised:
** (DBConnection.ConnectionError) tcp recv: closed
(db_connection) lib/db_connection/connection.ex:163: DBConnection.Connection.connect/2
(connection) lib/connection.ex:622: Connection.enter_connect/5
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
This answer on StackOverflow 提示这种错误通常发生在 Postgres 未运行时。所以我这样检查:
localhost:blog alex$ brew services list
Name Status User Plist
postgresql started
我还认为我的凭据不正确,因此我尝试使用 config/dev.exs 中的凭据手动登录 Postgres,如下所示:
localhost:blog alex$ psql postgres postgres -W
Password:
psql (11.3)
Type "help" for help.
postgres=#
我输入的密码是“postgres”。有人对这里可能发生的事情有任何建议吗?谢谢!
【问题讨论】:
-
我创建了一个新的 Phoenix 项目 -- 信息不足。
-
从 v10 开始,PostgreSQL 默认使用
5433端口进行加密连接。检查您的/etc/postgresql/10/main/postgresql.conf以获取port条目。 -
@AlekseiMatiushkin,我认为这不是端口问题。当我使用错误的端口时,我收到错误:(DBConnection.ConnectionError) tcp connect (localhost:55): connection denied - :econnrefused
-
@7stud 我的意思是我通过运行命令
mix phx.new blog创建了我的项目,抱歉含糊不清。
标签: postgresql elixir phoenix-framework ecto