How to change field type in Ecto?

Paulo Janeiro picture Paulo Janeiro · Sep 15, 2015 · Viewed 10.5k times · Source

I have a schema:

schema "editables" do
    field :title, :string
    field :content, :string

    timestamps
  end

Now I want to change the type of one field form :integer to :binary. What's the correct way of writing the migration because using add is not working...?

def change do
    alter table(:editables) do
      add :title, :binary
      add :content, :binary

      timestamps
    end
  end

Answer

Gazler picture Gazler · Sep 15, 2015

You have to use modify/3 to change the type. add/3 is only for adding new columns.

alter table(:editables) do
  modify :content, :binary
end