Creating the migration

We'll begin by creating the migration, as that's the foundation that will allow us to build and complete the rest of the code. Let's create a new migration as follows:

$ mix ecto.gen.migration add_user_id_to_polls* creating priv/repo/migrations* creating priv/repo/migrations/20171030030840_add_user_id_to_polls.exs

We'll need to do two things here: add the user ID column (which is a reference to the user's table) and create an index on user_id, shown as follows:

defmodule Vocial.Repo.Migrations.AddUserIdToPolls do  use Ecto.Migration  def change do    alter table(:polls) do      add :user_id, references(:users)    end    create index(:polls, [:user_id])  endend

Running the migration after this should result in no error messages, as shown ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.