Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content