Use smaller string column than varchar255

I want to create a column in one of the tables with a varchar2 and not more than that. By default string in ecto migration refers varchar255. So how can I use varchar2?

In migration simply write: :"varchar(2)" as a type or "varchar(2)" in latest ecto_sql (as String was not supported before).


Thank you :slight_smile:

You can also use the size option in the migration. Here’s an example from the ecto_sql tests:

Note how name is generated as a VARCHAR(20).


Ah, completely forgot about this option, nice find. In that case it’s worth to give some links to official API:

Each of those 3 mentions :size option. Both add/3 and modify/3 provides more useful options:


Thank you. This is a more clean option :slight_smile: