Ecto 3.0 apparently incompatible with mariarex - mysql

Hi there, I’m new to elixir. I’m trying to create a simple phoenix app with MySQL connection.
I’m using everything default that comes from the bundle.

Whenever I try running the application, I get this error:

function Ecto.Adapters.MySQL.Connection.child_spec/1 is undefined or private

Here’s some more details of the error:

==> db_connection
Compiling 23 files (.ex)
Generated db_connection app
==> phoenix
Compiling 60 files (.ex)
Generated phoenix app
==> phoenix_live_reload
Compiling 3 files (.ex)
Generated phoenix_live_reload app
==> mariaex
Compiling 14 files (.ex)
Generated mariaex app
==> ecto
Compiling 64 files (.ex)
warning: undefined behaviour function handle_deallocate/4 (for behaviour DBConnection)
  lib/ecto/adapters/sql/sandbox.ex:161

warning: undefined behaviour function handle_declare/4 (for behaviour DBConnection)
  lib/ecto/adapters/sql/sandbox.ex:161

warning: undefined behaviour function handle_first/4 (for behaviour DBConnection)
  lib/ecto/adapters/sql/sandbox.ex:161

warning: undefined behaviour function handle_next/4 (for behaviour DBConnection)
  lib/ecto/adapters/sql/sandbox.ex:161

warning: undefined behaviour function ensure_all_started/2 (for behaviour DBConnection.Pool)
  lib/ecto/adapters/sql/sandbox.ex:211

warning: unused import Ecto.Query.select/3
  lib/ecto/association.ex:1

warning: undefined behaviour function child_spec/1 (for behaviour Ecto.Adapters.SQL.Connection)
  lib/ecto/adapters/mysql/connection.ex:3

warning: undefined behaviour function execute/4 (for behaviour Ecto.Adapters.SQL.Connection)
  lib/ecto/adapters/mysql/connection.ex:3

warning: undefined behaviour function prepare_execute/5 (for behaviour Ecto.Adapters.SQL.Connection)
  lib/ecto/adapters/mysql/connection.ex:3

warning: function Mariaex.Connection.decode/2 is undefined or private
  lib/ecto/adapters/mysql/connection.ex:28

warning: function Ecto.Adapters.Postgres.Connection.all/1 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:56

warning: function Ecto.Adapters.Postgres.Connection.delete/4 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:56

warning: function Ecto.Adapters.Postgres.Connection.delete_all/1 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:56

warning: function Ecto.Adapters.Postgres.Connection.execute_ddl/1 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:56

warning: function Ecto.Adapters.Postgres.Connection.insert/5 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:56

warning: function Ecto.Adapters.Postgres.Connection.update/5 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:56

warning: function Ecto.Adapters.Postgres.Connection.update_all/1 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:56

warning: function Postgrex.start_link/1 is undefined (module Postgrex is not available)
  lib/ecto/adapters/postgres.ex:115

warning: function Ecto.Adapters.Postgres.Connection.execute/4 is undefined (module Ecto.Adapters.Postgres.Connection is not available)
  lib/ecto/adapters/postgres.ex:117

Generated ecto app
==> phoenix_ecto
Compiling 4 files (.ex)
Generated phoenix_ecto app
==> elixir_conslogv1
Compiling 12 files (.ex)
Generated elixir_conslogv1 app
[info] Application elixir_conslogv1 exited: ElixirConslogv1.start(:normal, []) returned an error: shutdown: failed to start child: ElixirConslogv1.Repo
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Ecto.Adapters.MySQL.Connection.child_spec/1 is undefined or private
            (ecto) Ecto.Adapters.MySQL.Connection.child_spec([name: ElixirConslogv1.Repo.Pool, otp_app: :elixir_conslogv1, repo: ElixirConslogv1.Repo, adapter: Ecto.Adapters.MySQL, username: "****", password: "****", database: "****", hostname: "localhost", pool_size: 10, pool_timeout: 5000, timeout: 15000, pool: DBConnection.Poolboy, adapter: Ecto.Adapters.MySQL, username: "****", password: "****", database: "****", hostname: "localhost", pool_size: 10])
            (ecto) lib/ecto/repo/supervisor.ex:92: Ecto.Repo.Supervisor.init/1
            (stdlib) supervisor.erl:294: :supervisor.init/1
            (stdlib) gen_server.erl:328: :gen_server.init_it/6
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
[info] Application mariaex exited: :stopped
[info] Application db_connection exited: :stopped
[info] Application connection exited: :stopped
[info] Application phoenix_ecto exited: :stopped
[info] Application ecto exited: :stopped
[info] Application poolboy exited: :stopped
[info] Application decimal exited: :stopped
[info] Application cowboy exited: :stopped
[info] Application cowlib exited: :stopped
[info] Application ranch exited: :stopped
[info] Application phoenix_html exited: :stopped
[info] Application phoenix_pubsub exited: :stopped

=INFO REPORT==== 24-Nov-2016::19:31:09 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application elixir_conslogv1: ElixirConslogv1.start(:normal, []) returned an error: shutdown: failed to start child: ElixirConslogv1.Repo
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Ecto.Adapters.MySQL.Connection.child_spec/1 is undefined or private
            (ecto) Ecto.Adapters.MySQL.Connection.child_spec([name: ElixirConslogv1.Repo.Pool, otp_app: :elixir_conslogv1, repo: ElixirConslogv1.Repo, adapter: Ecto.Adapters.MySQL, username: "root", password: "****", database: "****", hostname: "localhost", pool_size: 10, pool_timeout: 5000, timeout: 15000, pool: DBConnection.Poolboy, adapter: Ecto.Adapters.MySQL, username: "****", password: "****", database: "****", hostname: "localhost", pool_size: 10])
            (ecto) lib/ecto/repo/supervisor.ex:92: Ecto.Repo.Supervisor.init/1
            (stdlib) supervisor.erl:294: :supervisor.init/1
            (stdlib) gen_server.erl:328: :gen_server.init_it/6
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

I’ve searched for a similar problem and from what I see, it seems that ecto 3.0 is apparently incompatible with mysql, but I can’t be sure.

Here’s how my deps look like:

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

Any ideas?
1 Like

Ecto 3 has not been released yet. The latest version is ecto 2.0.5 (or 2.1 rc.4). (phoenix_ecto 3.0 depends of Ecto 2.0 I believe. Confusing? Yes :slight_smile: )

Ecto 2.0 should be compatible with Mariaex, see: https://github.com/elixir-ecto/ecto#usage

Have you run mix deps.update to make sure you have the correct versions?
Ecto.Adapters.MySQL.Connection.child_spec/1 was added in Ecto 2.0 so it looks like you have 1.1 or similar.

1 Like

I can reproduce the error. For a temporary fix while we investigate, please add the following to your deps list:

{:ecto, "~> 2.0"}
6 Likes

Thank you @josevalim and @Linuus your both suggestions worked very well for me. It’s interesting though that inside Phoenix 's entrails comes bundled that ecto v.3.0. It should come bundled with a 2.0 if that 3.0 is not working, correct?

Thanks again!

Phoenix does not come with Ecto 3.0 as a dependency because Ecto 3.0 does not exist :slight_smile:

It comes with phoenix_ecto 3.0 which integrates phoenix and ecto in some nice ways. However, phoenix_ecto 3.0 depends on ecto 2.0 as you can see here: https://hex.pm/packages/phoenix_ecto/3.0.1

Ecto 2.0 is working with Mariaex, since it worked when you added Ecto 2.0 as an explicit dependency. However, there is something odd going on here as @josevalim stated in his post. They will hopefully figure it out soon and fix it :slight_smile: In the meantime, just add the dependency on Ecto explicitly.

Good luck!

1 Like

Oops. This has been fixed 12 hours ago, I just forgot to report back. :slight_smile:

The issue was that a new Mariaex version was out and Hex had to go back to an outdated ecto and phoenix_ecto versions to satisfy those constraints. To fix it, I have released Ecto 2.0.6 with proper dependencies.

To be clear, it was not a Hex bug. Hex was just running dependency resolution. In fact, I think the real bug was that we published a stable phoenix_ecto 3.0.0 that depended on a release candidate version. If we haven’t done so, Hex would have picked proper versions for everything. I am currently talking to Eric to not allow such to be published to Hex or at least emit a warning to ensure publishers won’t make such mistakes in the future.

6 Likes

Thank you all for your help and quality explanation. Learning Elixir has been a daunting but a very exciting task.