What is the correct way to alter a ecto model in Phoenix?
So far I've created a Post model which contains a title and a content string field. I added the resource to the router to create and view the Posts.
Now I would like to add a author field to my model.
What I did until now is the following:
I created a migration with
mix ecto.gen.migration add_author_to_post
In the migrationfile I inserted
alter table(:posts) do
add :author, :string
end
and ran the migration with mix ecto.migrate.
Now the coloumn is visible in the database.
Then I added the fileld to my model file:
schema "posts" do
field :title, :string
field :content, :string
field :author, :string
timestamps
end
@required_fields ~w(title content author)
@optional_fields ~w()
But when I visit the page to add a new Post, there is no field to add an author in the html.file.
(The new.html.eex file was generated by the mix phoenix.gen.html)
PS: I'm sure this is a basic beginner question. But since the phoenixcommunity is quite small, this question might be usefull for lots of other people