I have a schema:
schema "editables" do
field :title, :string
field :content, :string
timestamps
end
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
来源:https://stackoverflow.com/questions/32583625/how-to-change-field-type-in-ecto