Settlement Dates Phoenix

Can someone help with what should be a stupid mistake that I'm afraid of. Consider these two fragments:

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 am trying to sow some data using

 cards = [ %Card{ creation_date: "2014-04-17", 

I got these simple lines from the things I found on the Internet; the alternative seemed to be {"2015", "04", "17"}.

** (Ecto.ChangeError) value "2014-04-17" for MosaicApi.Card.creation_date in insert does not match the Ecto.Date type

+5
source share
1 answer

Try the following:

 cards = [ %Card{ creation_date: %Ecto.Date{year: 2014, month: 4, day: 17}, 

Or:

 cards = [ %Card{ creation_date: Ecto.Date.cast!("2014-04-17"), 

Generators for tests were recently modified from the string format (which may be where you got this idea) https://github.com/phoenixframework/phoenix/commit/badf8065d0b025d6b6ad212bfa0b96e897f06a6a

+6
source

Source: https://habr.com/ru/post/1247939/


All Articles