How to remove a field from an 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 if this is the best / easiest way to do this (delete (column))? Can you set an example? I tried:

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

and it does not work.

+4
source share
1 answer

Instead of the create table, you want to use the alter / 2 table .

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

create/2 will grow if the table already exists.

+5
source

Source: https://habr.com/ru/post/1606856/


All Articles