10
votes

I would like to remove a field from an existing Ecto model:

field :age, :integer

After reading the docs I'm not sure what's the best/simple way of doing it (remove(column))?...Can you exemplify? I've tried:

def change do
    create table(:users) do
      remove :age
    end
end

and it's not working.

1

1 Answers

18
votes

You want to use alter/2 table instead of create table.

def change do
  alter table(:users) do
    remove :age
  end
end

create/2 will raise if the table already exists.