How to run updating in migration for Ecto?

荒凉一梦 提交于 2019-11-30 13:39:32
Dogbert

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!