FreedomBen
Hello, I am tearing my hair out trying to figure out why this doesn’t work. I am probably doing something dumb but I can’t figure it out. I’m very new to Elixir.
I’ve widdled my schema down to next to nothing to try and figure out what’s wrong. Here’s the migration:
defmodule TestApp.Repo.Migrations.CreateUsers do
use Ecto.Migration
def change do
create table(:users, primary_key: false) do
add :id, :binary_id, primary_key: true
add :username, :string, null: false
end
end
end
And the schema file:
defmodule TestApp.Accounts.User do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
schema "users" do
field :username, :string
end
def changeset(user, attrs) do
user
|> cast(attrs, [:username])
end
end
And then some code to insert a test object:
TestApp.Accounts.User.changeset(%TestApp.Accounts.User{}, %{username: "ben"})
|> TestApp.Repo.insert()
Running that produces this:
** (Protocol.UndefinedError) protocol String.Chars not implemented for %Postgrex.Query{columns: nil, name: "", param_formats: nil, param_oids: nil, param_types: nil, ref: nil, result_formats: nil, result_oids: nil, result_types: nil, statement: ["INSERT INTO ", [34, "users", 34], [], [32, 40, [[], 34, "id", 34], ") VALUES ", [], 40, [[], 36 | "1"], 41], []], types: nil}. This protocol is implemented for: Atom, BitString, Date, DateTime, Ecto.Date, Ecto.DateTime, Ecto.Time, Float, Integer, List, NaiveDateTime, Time, URI, Version, Version.Requirement
(elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir) lib/string/chars.ex:22: String.Chars.to_string/1
(ecto) lib/ecto/adapters/sql.ex:613: Ecto.Adapters.SQL.log/4
(db_connection) lib/db_connection.ex:1186: DBConnection.log/6
(db_connection) lib/db_connection.ex:591: DBConnection.prepare_execute/4
(ecto) lib/ecto/adapters/postgres/connection.ex:86: Ecto.Adapters.Postgres.Connection.execute/4
(ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
(ecto) lib/ecto/adapters/sql.ex:542: Ecto.Adapters.SQL.struct/8
(ecto) lib/ecto/repo/schema.ex:547: Ecto.Repo.Schema.apply/4
(ecto) lib/ecto/repo/schema.ex:213: anonymous fn/14 in Ecto.Repo.Schema.do_insert/4
(elixir) lib/code.ex:677: Code.require_file/2
(mix) lib/mix/tasks/run.ex:136: Mix.Tasks.Run.run/5
(mix) lib/mix/tasks/run.ex:76: Mix.Tasks.Run.run/1
(mix) lib/mix/task.ex:314: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:80: Mix.CLI.run_task/2
I’ve done mix ecto.drop && mix ecto.create && mix ecto.migrate and all goes fine. I’ve also verified in iex that the changeset is valid. But when passing the changeset to Repo.insert it blows up with that error.
What am I doing wrong? What are some good ways to go about debugging this?
Trending in Questions
One of my LiveView view’s has a very heavy javascript dependency so I want to avoid loading it for every page on the site, while still us...
New
Hi all!
I know that quite a few people use Phoenix LiveView but it is hard to get a more up-to-date list of folks/companies using it. I ...
New
I have a page in my Phoenix app with some LiveView code. When you click a button, it shows the Stripe credit card modal form via a Hook. ...
New
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hi everyone :waving_hand:
I’ve been working on PhiaUI, an open-source UI component library for Phoenix LiveView, and I wanted to share i...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #security
- #processes
- #api
- #forms
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
idi527
Why are you passing
:emailto changeset when it’s:usernamethat’s casted (and not null in the migration)?FreedomBen
Good catch, thanks, sorry that was a copy paste issue. I fixed the code above, and re-ran it locally and still get the same error.
script
try
autogenerate: falsein the schemaFreedomBen
Thank you. I changed the schema file to:
And got the same error message
I looked through the Ecto migration docs and didn’t see anything similar for the migration file. Is there anywhere else
autogenerateneeds to be declared?idi527
Where do you call
from?
FreedomBen
I have this code in
priv/repo/seeds.exsand run it withmix run priv/repo/seeds.exs:I have also tried the same in an
iexprompt started withiex -S mixwith identical results. A unit test for theAccountsmodule also yields the same error.idi527
Can you create a github repo with a way to reproduce the problem? It would help a lot since I don’t see anything wrong with your code snippets at all …
FreedomBen
Yes, that is a great idea. I’ll also spin up a DO droplet and try to reproduce it there, just in case there’s something wonky with my local setup. I tried nuking the postgres instance and spinning up a fresh one, but this error occurs before postgrex even sends the query.
idi527
The problem seems to be with ecto/lib/ecto/adapters/sql.ex at v2.2.10 · elixir-ecto/ecto · GitHub, which means postgrex queries don’t conform to string.chars protocol for some reason which is strange since they should …
FreedomBen
I am still waiting for permission from the client to post the entirety of the code, but I tried to reproduce the issue in a new project and have been unable to