Can anyone help with what must be a silly mistake I fear. Consider these two snippets:
defmodule MosaicApi.Repo.Migrations.CreateCard do
use Ecto.Migration
def change do
create table(:cards) do
add :creation_date, :date
and
defmodule MosaicApi.Card do
use MosaicApi.Web, :model
schema "cards" do
field :creation_date, Ecto.Date
I'm trying to seed some data using
cards = [
%Card{
creation_date: "2014-04-17",
I got these simple strings from things I found on the Internet; the alternative seemed to be {"2015", "04", "17"}.
** (Ecto.ChangeError) value
"2014-04-17"
forMosaicApi.Card.creation_date
ininsert
does not match type Ecto.Date
Try this:
cards = [
%Card{
creation_date: %Ecto.Date{year: 2014, month: 4, day: 17},
Or:
cards = [
%Card{
creation_date: Ecto.Date.cast!("2014-04-17"),
The generators for the tests were recently changed from the string format (which could be where you got the idea) https://github.com/phoenixframework/phoenix/commit/badf8065d0b025d6b6ad212bfa0b96e897f06a6a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With