fireproofsocks
Ecto Migration Field Types
There is a nice table showing the available data types used in Ecto Schemas: https://hexdocs.pm/ecto/Ecto.Schema.html#module-primitive-types
But I cannot find a corresponding list that enumerates the possibilities available to an Ecto Migration. They are similar, but they are not always the same. Does anyone have such a list? And should that be a part of the docs?
Many thanks!
Most Liked
kip
The list of types defined for Postgres is in postgrex extensions.
fireproofsocks
I figured out how to take advantage of PostGreSQL’s inet data type following Pedro’s excellent article:
add :ip, :inet, null: false, default: fragment("'0.0.0.0'::inet")
Note that you can just put whatever PostGres data type as the 2nd argument (no need to use fragment there). The fragment macro was however useful to supply a default argument for that field.
There is still the correlating types used by the schema, but this gets me so I’m able to create the database the way I want. Thanks all!
jswanner
255 is an old suggested default size for varchar, there were reason for it at the time, there’s no great reason to continue to use it anymore. For Postgres, unless you want to enforce some hard limit on the size of a string field, it’s best to use text as your default character field type.







