ActiveRecord Migrations

Flashcard 2 of 6

What is missing from this migration?

class CreateProjects < ActiveRecord::Migration
  def change
    create_table :projects do |t|
      t.string :title
      t.boolean :complete

      t.timestamps null: false
    end
  end
end

The complete field on the projects table should have a null: false to avoid having to potentially handle three values for the field (true, false, and null).

class CreateProjects < ActiveRecord::Migration
  def change
    create_table :projects do |t|
      t.string :title
      t.boolean :complete, null: false, default: false

      t.timestamps null: false
    end
  end
end

Read more in our blog post [Avoid the Three-state Boolean Problem][]

[Avoid the Three-state Boolean Problem]: https://robots.thoughtbot.com/avoid-the-threestate-boolean-problem

Return to Flashcard Results