尝试创建数据库时出错 - Ecto - Phoenix

Error when trying to create database - Ecto - Phoenix

我在尝试创建数据库时遇到错误。我已经安装了 postgres,并且已经成功地进行了一些测试项目。而且,我还没有看到这个错误。任何帮助都会很棒:

错误:

 ~/Desktop/elixir/restore $ mix ecto.create
** (Mix) The database for Restore.Repo couldn't be created: tcp connect: connection refused - :econnrefused

21:52:23.978 [error] GenServer #PID<0.150.0> terminating
** (Postgrex.Error) tcp connect: connection refused - :econnrefused
    (db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:623: Connection.enter_connect/5
    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol

我今天在尝试 运行 mix ecto.create 时遇到了同样的问题。 所以首先要确保你有 postgres。推荐使用brew安装。

brew 安装 postgres

使用 brew 服务 start/stop postgresql,

创建数据库,

创建 postgres 超级用户,

您可能需要授予对文件夹的权限。

这些链接对我很有用 :

psql: FATAL: role "postgres" does not exist

psql: FATAL: database "<user>" does not exist

我遇到了同样的问题,问题是 postgres 不是 运行ning。

所以,要检查这个,你应该 运行 :

brew services list

然后,如果您看到:

Name Status User Plist postgresql stopped

你应该 运行 :

brew services start postgresql

干杯!