[Ecto] Cannot set "autogenerate: true" when the primary key type of the embedded schema is :id

Ecto’s documentation does not clearly state whether it supports auto-increment. When I set this up, an incomprehensible error occurs.

@primary_key {:id, :id, autogenerate: true}
embedded_schema do
  # ...
end

Error:

** (CaseClauseError) no case clause matching: {:id, :id, :id}
code: {:ok, _} = Comic.create(build_params())
stacktrace:
  (ecto) lib/ecto/embedded.ex:141: Ecto.Embedded.autogenerate_id/5
  (ecto) lib/ecto/embedded.ex:112: Ecto.Embedded.to_struct/4
  (ecto) lib/ecto/embedded.ex:81: anonymous fn/6 in Ecto.Embedded.prepare_each/5
  (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
  (ecto) lib/ecto/embedded.ex:78: Ecto.Embedded.prepare_each/5
  (ecto) lib/ecto/embedded.ex:63: anonymous fn/6 in Ecto.Embedded.prepare/5
  (stdlib) maps.erl:232: :maps.fold_1/3
  (ecto) lib/ecto/repo/schema.ex:245: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
  (ecto) lib/ecto/repo/schema.ex:916: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/6
  (ecto_sql) lib/ecto/adapters/sql.ex:898: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
  (db_connection) lib/db_connection.ex:1415: DBConnection.run_transaction/4
  test/veemoe/business/comic_test.exs:18: (test)

2 Likes

So the embedded schema does not support the primary key integer increment?

I’m just facing this same error right now…
I wonder if it is is a bug?

Not sure how there’s a three-tuple getting to that function, but embeds don’t support autoincrement:

3 Likes