Data Types in Ecto – “value too long for type character varying(255)”

The error you get is from the underlying database where the column type is set to varchar which is what’s created by default when you specify the column type as string in a migration.

To store a variable length string over 255 characters, you need to specify the column type as text in the migration. You can convert the type of the existing column to text by using a migration such as:

alter table(:posts) do
  modify :content, :text
end

The field type in the schema section of the model should remain as string:

schema "posts" do
  field :content, :string
end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)