Trouble Upgrading to Ecto 3.1

I am having some trouble moving from Ecto 2.0 to 3.1. It seems to be that the default format for timestamps within Ecto has changed to not use microseconds. I’m OK with this, but I can’t find out where my changesets or schema are still injecting the DateTime objects with microseconds as opposed to just using the default format.

I have tried dropping and recreating my database several times, but I continuously get errors like the following when inserting:

(ArgumentError) :utc_datetime expects microseconds to be empty, got: ~U[2019-09-04 01:09:48.746549Z]
Use `DateTime.truncate(utc_datetime, :second)` (available in Elixir v1.6+) to remove microseconds.

This is from just trying something as simple as Repo.insert(%SomeChangesetStruct{}) with a changeset that has timestamps() defined in its schema.

Is there a configuration option I’m missing? I’ve gone through the Ecto Getting Started guide and can’t seem to find any differences between my setup and theirs. I’m imagining if I’ve dropped and recreated the database, it should be using the (truncated) correct timestamps (in fact, my psql database gives the following for inserted_at and updated_at for the above struct, which I believe is correct).

inserted_at | timestamp(0) without time zone | not null                                            | plain    |              | 
 updated_at  | timestamp(0) without time zone | not null                                            | plain    |              |

Any help is appreciated.

This turned out to be an issue with ExAudit 0.6.

Github issue is here.

3 Likes