如何在Ecto中更改字段类型? [英] How to change field type in Ecto?
本文介绍了如何在Ecto中更改字段类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模式:
schema "editables" do
field :title, :string
field :content, :string
timestamps
end
现在,我想将一个字段的类型从:integer
更改为:binary
.
编写迁移的正确方法是什么,因为使用add
不起作用...?
Now I want to change the type of one field form :integer
to :binary
.
What's the correct way of writing the migration because using add
is not working...?
def change do
alter table(:editables) do
add :title, :binary
add :content, :binary
timestamps
end
end
推荐答案
You have to use modify/3 to change the type. add/3
is only for adding new columns.
alter table(:editables) do
modify :content, :binary
end
这篇关于如何在Ecto中更改字段类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文