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
Ecto provides two types of custom types: basic types and parameterized types. Basic types are simple, requiring only four callbacks to be implemented, and are enough for most occasions. Parameterized types can be customized on the field definition and provide a wide variety of callbacks.
Migration behaviour (Ecto SQL v3. 8.3) Migrations are used to modify your database schema over time. This module provides many helpers for migrating the database, allowing developers to use Elixir to alter their storage in a way that is database independent.
8.4) Changesets allow filtering, casting, validation and definition of constraints when manipulating structs. There is an example of working with changesets in the introductory documentation in the Ecto module. The functions cast/4 and change/2 are the usual entry points for creating changesets.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With