2FO
Error: "no function clause matching in Keyword.get/3" when calling Ecto.changset
I’m running into the following errors, going through the Ecto getting started docs.
Calling
person = %Friends.Person{}
changeset = Friends.Person.changeset(person, %{})
Produces
** (FunctionClauseError) no function clause matching in Keyword.get/3
The following arguments were given to Keyword.get/3:
# 1
:last_name
# 2
:trim
# 3
true
Attempted function clauses (showing 1 out of 1):
def get(keywords, key, default) when is_list(keywords) and is_atom(key)
(elixir 1.13.3) lib/keyword.ex:352: Keyword.get/3
(ecto 3.8.4) lib/ecto/changeset.ex:1796: Ecto.Changeset.validate_required/3
person.ex
defmodule Friends.Person do
use Ecto.Schema
schema "people" do
field(:first_name, :string)
field(:last_name, :string)
field(:age, :integer)
end
def changeset(person, params \\ %{}) do
person
|> Ecto.Changeset.cast(params, [:first_name, :last_name, :age])
|> Ecto.Changeset.validate_required(:first_name, :last_name)
end
end
migration
defmodule Friends.Repo.Migrations.CreatePeople do
use Ecto.Migration
def change do
create table(:people) do
add :first_name, :string
add :last_name, :string
add :age, :integer
end
end
end
Marked As Solved
benwilson512
Author of Craft GraphQL APIs in Elixir with Absinthe
Hey @2FO welcome! The issue is that this line here should be:
|> Ecto.Changeset.validate_required([:first_name, :last_name])
Basically you’re passing in the atom :last_name into the argument that would be the options value. To pass in multiple fields that should be required you should use a list.
2
Popular in Questions
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
I would like to know what is the best IDE for elixir development?
New
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”:
14:57:30.512 [warn] ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New







