Hi,
I am still very new to Elixir/Phoenix/Ecto. I have a question regarding migrations. You can use a command
$ mix phoenix.gen.html User users name:string email:string bio:string number_of_pets:integer
$ mix ecto.migrate
to generate the Ecto model. This command generates the initial migration file for you. Now if I want to say add a new field to this model (for e.g. “address:string”), how do I go about doing it? Please tell me if I am doing something wrong here
-
Create a new migration file named YYYYMMDDSSSSSS_alter_users.exs in repo/migrations directory with contents as follows
defmodule HelloPhoenix.Repo.Migrations.AlterUser do
use Ecto.Migrationdef change do
alter table(:users) do
add :address, string
add :usertype_id, references(:usertypes, on_delete: :nothing)
end
end -
run $mix ecto.migrate
How will Ecto know to not run other migration files already in the repo/migrations directory? I don’t want to run something and find out that I messed up big time.
Thanks
Sudheer