How do I update a schema with new fields and migrate the changes?

I have the following schema that I generated in the database:

 schema "users" do
    field(:email, :string)
    field(:firstname, :string)
    field(:lastname, :string)
    field(:password_hash, :string)

    timestamps()
  end

I want to add a subscribed field that is a boolean and has a default of false.

  schema "users" do
    field(:email, :string)
    field(:firstname, :string)
    field(:lastname, :string)
    field(:password_hash, :string)
    field(:subscribed, :boolean, default: false)

    timestamps()
  end

How do I do this and update the database to reflect it ?

I think I found the answer to this here:

https://stackoverflow.com/questions/33393808/how-do-i-update-files-created-by-phoenix-gen-ht the-phoenix-framework

1 Like