As mentioned at the end of class, you're now equipped with everything you need to know to add a
new field our app with one exception. Our first database migration used the create/2
function
to create the table and add our initial fields. We need to use the alter/2
function make
modifications such as adding/modifying/or removing fields.
You can run mix ecto.gen.migration add_new_field
to get something that looks like
this (pay close attention to the snake case in add_new_field
):
defmodule AnnieMae.Repo.Migrations.AddNewField do
use Ecto.Migration
def change do
alter table("anime") do
add :genre, :string
end
end
end
Notice my addition of the alter/2
function in the migration. Once you've made your change, you can run mix ecto.migrate
to apply your migration to your database. If you change your mind, you can use mix ecto.rollback
to unapply the
migration from your database.