Search code examples
elixirphoenix-frameworkecto

How to change field type in Ecto?


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

Solution

  • 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