I use Phoenix and Ecto in one of my project.
I want to add a column to one table, and I expect it to be a NOT NULL column. But I already have some existed d
Solution #2 is the correct approach, but you need to add a call to Ecto.Migration.flush/0 after the first alter
block to make sure all the changes are executed on the database instantly instead of being queued up to be executed later, which is the default.
def up do
alter table(:channels) do
add :type, :integer
end
flush()
Exchat.Repo.update_all("channels", set: [type: 1])
alter table(:channels) do
modify :type, :integer, null: false
end
end