简体   繁体   中英

How can I connect to Postgres with mix command on Phoenix framework?

I am trying to run mix ecto.create on Phoenix project and got error:

00:30:34.332 [error] GenServer #PID<0.328.0> terminating 
    (RuntimeError) Connect raised a CaseClauseError error. The exception details are hidden, as they may contain sensitive data such as database credentials.
    (postgrex) lib/postgrex/utils.ex:40: Postgrex.Utils.parse_version/1
    (postgrex) lib/postgrex/protocol.ex:497: Postgrex.Protocol.bootstrap_send/4
    (postgrex) lib/postgrex/protocol.ex:353: Postgrex.Protocol.handshake/2
    (db_connection) lib/db_connection/connection.ex:135: 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 Discuss.Repo couldn't be created: an exception was raised:
(RuntimeError) Connect raised a CaseClauseError error. The exception details are hidden, as they may contain sensitive data such as database credentials.
        (postgrex) lib/postgrex/utils.ex:40: Postgrex.Utils.parse_version/1
        (postgrex) lib/postgrex/protocol.ex:497: Postgrex.Protocol.bootstrap_send/4
        (postgrex) lib/postgrex/protocol.ex:353: Postgrex.Protocol.handshake/2
        (db_connection) lib/db_connection/connection.ex:135: 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

My config/dev.exs

# Configure your database
config :discuss, Discuss.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: "elixir",
  password: "Ohtai3ai",
  database: "discuss_dev",
  hostname: "127.0.0.1",
  pool_size: 10

My Elixir version is 1.6.6 (compiled with OTP 19) Postgres 10

Out of date postgrex dependency could be the reason, try upgrading it.

mix deps.update postgrex

The solution comes from postgrex issue #370 which is easily found by googling the exact error message .

Resolved. Just update new versions for phoenix_ecto 3.3.0 postgrex 0.13.5 ecto 2.2.10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM