Ruby/Rails Features and Patterns

Flashcard 5 of 6

Is there anything we can add to the migration below so that Posts are guaranteed to have referential integrity (meaning a post's user_id will always point to a user row that actually exists in the database)?

class AssociatePostsWithUsers < ActiveRecord::Migration
  def change
    add_column :posts,
               :user_id,
               null: false,
               index: true
  end
end

Answer:

Reveal Answer