$ mix phx.gen.context Cars Car cars ts:timestamp
But this error was given:
** (Mix) Unknown type `:timestamp` given to generator. The supported types are: array, binary, boolean, date, decimal, enum, float, integer, map, naive_datetime, naive_datetime_usec, references, string, text, time, time_usec, utc_datetime, utc_datetime_usec, uuid
Any idea what option from the error message options should I choose so the format is compatible with the Postgres’s
timestamp ? In other words which should I use so they are the same as
inserted_at columns that are automatically created by Phoenix?
The answer to your question is over there: https://hexdocs.pm/ecto/Ecto.Schema.html#module-the-datetime-types. It all comes down to what you’re looking for, the
:naive_datetime types should be ok (the
usec version has microseconds precision, if you need it).
I want that option which is used by Phoenix by default, e.g. for scheme_migrations table and inserted_at column. Which one is that?
Does Postgres support microseconds? How much more bytes per one record is that versus without microseconds?
Is there some compatibility issues with
naive_datetime? For example winter summer time changes, etc.?
:naive_datetime. You can see the default timestamp applied (when using the
timestamp() function in your schema) on the schema attributes doc here (in the @timestamp_opts) and in the migrations function here
What about this issue? Why use `utc_datetime` over `naive_datetime` for Ecto? - #2 by LostKobrakai
It seems that I should use
utc_datetime instead of your suggestion
Definitely use :utc_datetime_*. In hindsight, we wish we made that the default in Ecto but now we can’t due to backwards compatibility (and there are no plans for Ecto 4)
This seems to be quite polarizing topic. It would be great to know the opinion of Phoenix veterans what version they use in their projects.
You’ve asked to get what Ecto is putting by default, and that’s
:naive_datetime. I don’t have any idea what you’re trying to do with it. What you actually need depends on requirements.
I have find this interesting article:
He claims that:
utc_datetime in the Ecto schemas and
timestamptz in migrations.
Seems like I shouldn’t use
naive_datetime, or? Do you have any experience with this?
From what i know,
:naive_datetime are there for backwards compatibility (hence the defaults). I only use
utc_* in my projects (because i need UTC, but also because i don’t see a reason to use
:naive_* unless having a good reason to do so).
With that said, if you’re just working towards a pet project to train yourself, i wouldn’t bother with it at the moment (the default will do the job just fine, unless you are actually going to work with timestamps that requires timezone stuff).
because i need UTC
Can I ask why do you need UTC?