ActiveRecord Migrations

Flashcard 6 of 6

Is there anything we could add to the following migration to ensure that actions will only be able to reference projects that actually exist in our system?

class CreateActions < ActiveRecord::Migration
  def change
    create_table :actions do |t|
      t.string :title
      t.references :project

      t.timestamps null: false
    end

    add_index :actions, :project_id
  end
end

Answer:

Reveal Answer