April 2018
Beginner to intermediate
406 pages
9h 33m
English
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 ...