# Ecto.create failure

**URL:** <https://forum.elixirforum.com/t/ecto-create-failure/29723>\
**Category:** Questions\
**Tags:** ecto, phoenix, postgres, postgresql\
**Created:** [March 9, 2020, 11:36am UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723 "2020-03-09T11:36:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![max\_wen](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@max\_wen](https://forum.elixirforum.com/u/max_wen)\
**Post date:** [March 9, 2020, 11:36am UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/1 "2020-03-09T11:36:05Z")

</div>

i am following along with the Phoenix Up & Running guide at [https://phoenixframework.readme.io/docs/up-and-running](https://phoenixframework.readme.io/docs/up-and-running)  
and when I try to use ecto to create a database (Postgresql) I get the following error

> $ mix ecto.create
> 
> 17:55:35.631 [error] GenServer #pid\<0.215.0\> terminating  
> \*\* (RuntimeError) Connect raised a CaseClauseError error. The exception details are hidden, as they may contain sensitive data such  
> as database credentials.
> 
> ```
> (postgrex 0.12.2) lib/postgrex/utils.ex:40: Postgrex.Utils.parse_version/1
> (postgrex 0.12.2) lib/postgrex/protocol.ex:497: Postgrex.Protocol.bootstrap_send/4
> (postgrex 0.12.2) lib/postgrex/protocol.ex:353: Postgrex.Protocol.handshake/2
> (db_connection 1.1.3) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
> (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
> (stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
> 
> ```
> 
> Last message: nil

> State: Postgrex.Protocol

> \*\* (Mix) The database for HelloPhoenix.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 0.12.2) lib/postgrex/utils.ex:40: Postgrex.Utils.parse_version/1
> (postgrex 0.12.2) lib/postgrex/protocol.ex:497: Postgrex.Protocol.bootstrap_send/4
> (postgrex 0.12.2) lib/postgrex/protocol.ex:353: Postgrex.Protocol.handshake/2
> (db_connection 1.1.3) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
> (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
> (stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
> 
> ```

The only suggestions I found was to update Postgrex. I ran `mix deps.update postgrex` and this did not fix it.

Finally I checked config/dev.exs and username/password are set to “postgres”. I used PgAdmin3 to confirm this is a valid login.

So at this point I am stuck.

Ubuntu 19.10

postgres (PostgreSQL) 11.7 (Ubuntu 11.7-0ubuntu0.19.10.1)  
installed from Ubuntu repo via apt-get

thanks

---

<div class="post-metadata">

**Author:** ![benwilson512](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/32/1457_2.png) [@benwilson512](https://forum.elixirforum.com/u/benwilson512)\
**Post date:** [March 9, 2020, 11:37am UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/2 "2020-03-09T11:37:59Z")

</div>

Try setting `show_sensitive_data_on_connection_error: true` in the config block for your repo.

---

<div class="post-metadata">

**Author:** ![max\_wen](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@max\_wen](https://forum.elixirforum.com/u/max_wen)\
**Post date:** [March 9, 2020, 1:11pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/3 "2020-03-09T13:11:07Z")

</div>

Thanks.

I had to google to find how to update that setting and it seems to be a common question. Based on another ElixirForum answer I updated config.exs thus

```elixir
> # This file is responsible for configuring your application
> # and its dependencies with the aid of the Mix.Config module.
> #
> # This configuration file is loaded before any dependency and
> # is restricted to this project.
> use Mix.Config
> 
> # General application configuration
> config :hello_phoenix,
> ecto_repos: [HelloPhoenix.Repo]
> 
> config :hello_phoenix, HelloPhoenix.Repo,
> show_sensitive_data_on_connection_error: true
> 
> # Configures the endpoint
> config :hello_phoenix, HelloPhoenix.Endpoint,
> url: [host: "localhost"],
> secret_key_base: "+zOPUugL3TISBlX4gNLI9tMhjgxP94HKofCcGqooGzkgoUCojlUJJal7QMacPgGw",
> render_errors: [view: HelloPhoenix.ErrorView, accepts: ~w(html json)],
> pubsub: [name: HelloPhoenix.PubSub,
> adapter: Phoenix.PubSub.PG2]
> 
> # Configures Elixir's Logger
> config :logger, :console,
> format: "$time $metadata[$level] $message\n",
> metadata: [:request_id]
> 
> # Import environment specific config. This must remain at the bottom
> # of this file so it overrides the configuration defined above.
> import_config "#{Mix.env}.exs"

```

and still I get the following error on mix ecto.create

```elixir
21:03:52.509 [error] GenServer #PID<0.327.0> terminating
** (RuntimeError) Connect raised a CaseClauseError error. The exception details are hidden, as
they may contain sensitive data such as database credentials.

    (postgrex 0.12.2) lib/postgrex/utils.ex:40: Postgrex.Utils.parse_version/1
    (postgrex 0.12.2) lib/postgrex/protocol.ex:497: Postgrex.Protocol.bootstrap_send/4
    (postgrex 0.12.2) lib/postgrex/protocol.ex:353: Postgrex.Protocol.handshake/2
    (db_connection 1.1.3) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
    (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for HelloPhoenix.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 0.12.2) lib/postgrex/utils.ex:40: Postgrex.Utils.parse_version/1
        (postgrex 0.12.2) lib/postgrex/protocol.ex:497: Postgrex.Protocol.bootstrap_send/4
        (postgrex 0.12.2) lib/postgrex/protocol.ex:353: Postgrex.Protocol.handshake/2
        (db_connection 1.1.3) lib/db_connection/connection.ex:135: DBConnection.Connection.connect/2
        (connection 1.0.4) lib/connection.ex:622: Connection.enter_connect/5
        (stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

```

should the setting be updated differently? thanks

---

<div class="post-metadata">

**Author:** ![1player](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/1player/32/14000_2.png) [@1player](https://forum.elixirforum.com/u/1player)\
**Post date:** [March 9, 2020, 1:58pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/4 "2020-03-09T13:58:10Z")

</div>

I don’t know exactly what is going on but `postgrex` seems to be failing parsing a version, I expect the database’s…

You’re on PostgreSQL 11.7 which is from Feb 2020, but your `postgrex` _is very old_: v0.12.2 was released in Sep 2016.

Try updating your `postgrex` library version, the latest is v0.15.3.

```elixir
mix deps.unlock postgrex
mix deps.update postgrex

```

And/or change the version requirement in your mix.exs file

---

<div class="post-metadata">

**Author:** ![max\_wen](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@max\_wen](https://forum.elixirforum.com/u/max_wen)\
**Post date:** [March 9, 2020, 2:48pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/5 "2020-03-09T14:48:55Z")

</div>

```elixir
$ mix deps.unlock postgrex
$ mix deps.update postgrex
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:52

Resolving Hex dependencies...
Dependency resolution completed:
Unchanged:
  connection 1.0.4
  cowboy 1.1.2
  cowlib 1.0.2
  db_connection 1.1.3
  decimal 1.8.1
  ecto 2.0.6
  file_system 0.2.8
  gettext 0.17.4
  mime 1.3.1
  phoenix 1.2.5
  phoenix_ecto 3.0.0
  phoenix_html 2.10.5
  phoenix_live_reload 1.1.7
  phoenix_pubsub 1.1.2
  plug 1.3.6
  poison 2.2.0
  poolboy 1.5.2
  ranch 1.3.2
New:
  postgrex 0.12.2

```

Ran your commands and it installs 0.12.2 again. Why wouldn’t it install the latest?

---

<div class="post-metadata">

**Author:** ![lucaong](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/32/21794_2.png) [@lucaong](https://forum.elixirforum.com/u/lucaong)\
**Post date:** [March 9, 2020, 2:50pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/6 "2020-03-09T14:50:55Z")

</div>

Can you show your `deps` in `mix.exs`? Most likely, `postgrex` is pinned to a specific version.

If that’s the case, you can change the version pinning to something like `~> 0.15`.

---

<div class="post-metadata">

**Author:** ![max\_wen](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@max\_wen](https://forum.elixirforum.com/u/max_wen)\
**Post date:** [March 9, 2020, 2:53pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/7 "2020-03-09T14:53:52Z")

</div>

```elixir
  defp deps do
    [{:phoenix, "~> 1.2.5"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.0"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"}]
  end

```

this is the default setting after `mix phoenix.new`

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [March 9, 2020, 2:54pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/8 "2020-03-09T14:54:11Z")

</div>

Because there is a lot more of dated dependencies, probably something puts a constraint on `postgrex` that makes it unable to update.

If you put `{:postgrex, "~> 0.13"}` in your `mix.exs` and then `mix do deps.unlock postgrex, deps.update postgrex` again, it will tell you where constraints are comming from.

PS: Also do not put `>=` as a version constraint unless you really know what you are doing.

PPS: `ecto` 2.0.6 had a constraint on `postgrex` that basically narrows it to `0.12.x`.

PPPS: You really should ditch that old, outdated and deprecated guide in favor of the new hexdocs hosted: [Up and Running — Phoenix v1.8.8](https://hexdocs.pm/phoenix/up_and_running.html), how have you actually found that other one? Those aren’t linked from the phoenix homepage anymore for years…

---

<div class="post-metadata">

**Author:** ![max\_wen](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@max\_wen](https://forum.elixirforum.com/u/max_wen)\
**Post date:** [March 9, 2020, 3:03pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/9 "2020-03-09T15:03:26Z")

</div>

ok thank you but I did not put that. this is the default mix.exs file. but what you say makes sense. here is the result

```elixir
Resolving Hex dependencies...

Failed to use "db_connection" because
  ecto (version 2.0.6) requires ~> 1.0
  postgrex (versions 0.14.0 to 0.14.3) requires ~> 2.0
  mix.lock specifies 1.1.3

Failed to use "db_connection" because
  ecto (version 2.0.6) requires ~> 1.0
  postgrex (versions 0.15.0 to 0.15.3) requires ~> 2.1
  mix.lock specifies 1.1.3

Failed to use "postgrex" (versions 0.13.0 to 0.13.5) because
  ecto (version 2.0.6) requires ~> 0.12.0
  mix.exs specifies ~> 0.13

```

so how do I decipher this? Does ecto need updating? thx

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [March 9, 2020, 3:06pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/10 "2020-03-09T15:06:38Z")

</div>

As I said already, the best is to ditch the guide you follow, and remove the empty project you have so far. Then you `mix archive.uninstall phoenix_new`, as that is deprecated and only creates outdated project skeletons.

Then you start again by following the [new guide](https://hexdocs.pm/phoenix/up_and_running.html), updating all those dependencies like NodeJS, Elixir, Erlang while you go, though at least the latter two usually do not need extra updating.

---

<div class="post-metadata">

**Author:** ![max\_wen](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/9f8e36/32.png) [@max\_wen](https://forum.elixirforum.com/u/max_wen)\
**Post date:** [March 9, 2020, 3:08pm UTC](https://forum.elixirforum.com/t/ecto-create-failure/29723/11 "2020-03-09T15:08:27Z")

</div>

sorry i did not read the 3rd PS. I will do that and follow the new guide on hexdocs. thanks again.

```elixir
$ mix archive.uninstall phoenix_new
Are you sure you want to uninstall /home/max/.mix/archives/phoenix_new? [Yn] Y

```

Done!

UPDATE: I followed the Install instructions and Up and Running at hexdocs.pm and saw the Phoenix Framework page being served on localhost. No hiccups even with ecto. thanks for the assistance.
