small medium large xlarge

Img_20170307_203606_pragsmall
17 Apr 2017, 20:22
Lee Sigauke (1 post)

I’m currently on chapter 7 of programming phoenix and I seem to have hit a snag, which I have solved but it’s been bugging me why the code in the book doesn’t work for me; so if anyone can give me an answer, that would be awesome.

So the migration from the book is laid out like this

 def change do
    alter table(:videos) do
      add :category_id, references(:categories)
    end
  end

However, when I run the migration then pull all the columns from my videos table, I can never see the category_id column in my table, the only way I could get it to show/be created was to make another migration and add the category_id as an index (below)

def change do
    alter table(:videos) do
      add :category_id, references(:categories)
    end
    create index(:videos, [:category_id])
  end

Making this change also has a knock on effect on my changeset for a Category, instead of assoc_constraint, I’m having to use foreign_key_constraint.

Did I miss something here? or did something change between the version of phoenix in this book and the one I have (1.2.1)

You must be logged in to comment