Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a field from Ecto model

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.

like image 784
Paulo Janeiro Avatar asked Sep 10 '15 19:09

Paulo Janeiro


1 Answers

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.

like image 139
Gazler Avatar answered Oct 01 '22 03:10

Gazler